Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Cdaprod/c96457acdc615c9d15c58af49e6ba7af to your computer and use it in GitHub Desktop.
Save Cdaprod/c96457acdc615c9d15c58af49e6ba7af to your computer and use it in GitHub Desktop.
For testing template injection on a page
const { Builder, By, Key, until } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const templateInjectionPayloads = [
'{{7*7}}', // Basic expression evaluation. Should return 49 if template injection is possible
'${7*7}', // This is for template engines that use $ like in AngularJS
'<%= 7 * 7 %>', // This is for EJS style templates
// Add more payloads to test different template engines
];
const url = 'http://your-website.com';
const inputField = 'input#your-input-field-id';
async function testTemplateInjection() {
let driver = await new Builder().forBrowser('chrome').setChromeOptions(new chrome.Options().headless()).build();
try {
await driver.get(url);
for (let payload of templateInjectionPayloads) {
await driver.findElement(By.css(inputField)).clear();
await driver.findElement(By.css(inputField)).sendKeys(payload, Key.RETURN);
// You will need to implement the code to check if the payload was successful
}
} finally {
await driver.quit();
}
}
testTemplateInjection();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment