Cross-site Scripting, also known as XSS, is a security vulnerability that occurs when a user is able to input data into a webpage or access session information.
HOW TO PROTECT
It is crucial to never allow code injection on your webpage. Make sure to validate any form inputs on the server side before displaying them on the page.
Avoid allowing changes to the page content through the href
attribute. Always escape the data properly before using it in your code.
For more information on protecting against XSS, check out this answer on location.href
:
SAMPLE:
Imagine you have an iframe that changes based on a GET variable:
sample.tld/index.jsp?iframe=none.jsp
An attacker could potentially inject a malicious script
into your iframe. To prevent this, always use escape characters to sanitize the data.
// Sanitize the input on the server and ensure the GET variable for the iframe remains secure.