Definition: A type of security vulnerability where an attacker injects malicious code or scripts into a web application.
Consequences: Can lead to sensitive data theft, user session hijacking, website defacement, or malware distribution.
Static Website:
Comprised of pre-created files such as HTML, CSS, and JavaScript.
HTTP Request from a web browser results in a static HTTP Response from the web server.
Dynamic Website:
Involves interactive data from databases, utilizing server-side scripting to generate dynamic content.
HTTP GET/POST requests manipulate data, which can include user inputs, cookies, etc.
Definition: A security mechanism that restricts how documents or scripts can interact from different origins.
Components of an origin:
Protocol: e.g., http:// or https://
Domain: Hostname such as example.com
Port Number: e.g., :80, :443.
Example: The same-origin policy permits:
https://example.com/page1.html
https://example.com/page2.html
Cross-Origin: Any difference in protocol, domain, or port is labeled as Cross-Origin.
Definition: A type of script injection attack that allows an attacker to run malicious JavaScript in a user's browser.
Mechanism: Victims are tricked into visiting a compromised website that delivers the malicious script, disguised as legitimate content.
Example: User comments section where malicious scripts are injected.
Website: Serves HTML pages to users.
Victim: Unwitting user of the website.
Attacker: Malicious user targeting the victim via an XSS vulnerability.
Reflected XSS:
Malicious scripts come from the current HTTP request.
The website reflects back the malicious string immediately in the response.
Stored XSS:
Malicious scripts are stored in the website's database and served to users when they visit the webpage.
DOM-based XSS:
Vulnerabilities exist in client-side code manipulation. Attacks occur entirely on the client-side.
Mechanism:
Attacker crafts URL with a malicious string.
Victim is tricked into clicking the URL.
Server includes the malicious string in the response.
The victim’s browser executes it, potentially stealing cookies.
Impact: Complete user compromise; attacker gains access to the victim's permissions.
Test Every Entry Point: Check input across all user inputs: URL parameters, forms, etc.
Submit Random Values: Send unique alphanumeric strings and look for reflections in responses.
Test XSS Payloads: Insert scripts like <script>alert(1)</script>
.
Mechanism:
Attackers inject JavaScript code through input fields that store data, like review comments.
Every visit prompts the injected code to execute, potentially stealing session cookies.
Danger: Can continuously affect all users visiting the compromised content.
Definition: A type of Cross-Site Scripting where the attack is executed entirely on the client side, manipulating the Document Object Model (DOM) in the victim's browser.
Mechanism: Vulnerabilities typically exist in client-side scripts that allow attackers to modify the DOM. The attack occurs when the client-side code processes data from untrusted sources, leading to the execution of malicious scripts.
Example: An attacker might exploit a vulnerable website that uses URL fragments or query parameters to control DOM elements, allowing them to inject malicious script that the browser then executes.
Prevention: JavaScript should properly validate and sanitize any data used within the DOM, avoiding internal functions that can allow for code execution unless necessary and secured.
WAF (Web Application Firewall): Uses filtering methods to block malicious attempts.
Whitelisting: Only allow specific characters or patterns from user inputs.
Content Security Policy (CSP): Restricts resource execution based on the defined policy, blocking unauthorized scripts.
DOM-based XSS Mitigation: Validate, sanitize inputs and avoid unsafe manipulation of the DOM.
Definition: A vulnerability whereby unauthorized actions are executed on a web app on behalf of an authenticated user via their browser.
Mechanism: User logs in, receives authentication, then unwittingly executes an attack by visiting a malicious page that sends requests to a legit app.
CSRF Tokens: Unique tokens per session to verify request authenticity.
SameSite Cookies: Prevent cookies from being sent in cross-origin requests.
Referrer Policy: Limit referrer headers across sites to reduce attacks.
Validation of Token in Critical Actions: Extra security in sensitive operations such as fund transfers or password changes.