In-depth lesson · XSS
Typical fixes
Every point the XSS reports back under this heading, best-backed first, each with the reports it is seen in.
-
Apply context-appropriate output encoding for HTML, attribute and JavaScript contexts.
Seen in 20 reports
-
Sanitise uploaded files and serve them with a safe content type or force download.
Seen in 9 reports
-
HTML-encode filenames, names and user text before inserting them into pages, and use text insertion rather than HTML insertion where markup is not intended.
Seen in 6 reports
-
Properly encode and validate user-supplied input reflected in URLs.
Seen in 5 reports
-
Encode name fields before inserting them into email templates.
Seen in 4 reports
-
Encode user input before reflecting it into HTML responses.
Seen in 4 reports
-
Listeners should validate the sender origin before acting on message content.
Seen in 4 reports
-
Validate actual file content and serve uploads with a safe content type rather than trusting the extension.
Seen in 4 reports
-
Validate actual file content with magic bytes and serve uploads with a safe Content-Type and a restrictive CSP or sandbox.
Seen in 4 reports
-
Validate the actual content of uploaded files rather than trusting the extension, and serve user files from a separate origin.
Seen in 4 reports
-
Apply context-aware output encoding when writing URL parameters into the DOM.
Seen in 3 reports
-
Check the sender origin against an exact allowlist and sanitise message content before inserting it.
Seen in 3 reports
-
Disable the TRACE method on the web server.
Seen in 3 reports
-
Do not modify sanitised output afterwards, and re-sanitise after any server-side rewrite.
Seen in 3 reports
-
Encode or filter HTML characters in reflected URL content.
Seen in 3 reports
-
Encode reflected input and block event-handler attributes on all elements, not just script tags.
Seen in 3 reports
-
Encode user input on output rather than relying on blacklists of tags or attributes.
Seen in 3 reports
-
Encode user input on output rather than relying on client-side or keyword filters.
Seen in 3 reports
-
Escape user messages before rendering them as HTML.
Seen in 3 reports
-
Reject control characters and javascript schemes in return and redirect URLs, and parse URLs consistently with browsers.
Seen in 3 reports
-
Sanitise SVG content and restrict active content before serving uploaded files.
Seen in 3 reports
-
Sanitise SVG uploads and serve them from a separate origin with a strict CSP.
Seen in 3 reports
-
Serve uploaded files with a safe content type and a Content-Disposition header, and do not serve user HTML from the application origin.
Seen in 3 reports
-
Validate and encode user-supplied data in device management endpoints.
Seen in 3 reports
-
Validate link targets in markup renderers and reject javascript: URLs.
Seen in 3 reports
-
Validate that redirect parameters are safe http(s) URLs and reject javascript: schemes.
Seen in 3 reports
-
Validate URL schemes against an allowlist before placing values into href or iframe sources.
Seen in 3 reports
-
Apply output encoding to user input reflected by incentive endpoints.
Seen in 2 reports
-
Check the origin of incoming postMessage events before acting on them.
-
Encode and validate parameters written into HTML attributes.
-
Encode quotes in parameters inserted into HTML attributes.
Seen in 2 reports
-
Medium -
Medium
-
-
Encode the quote character and angle brackets when reflecting input into an HTML attribute value.
-
Escape the code parameter before placing it in inline JavaScript.
Seen in 2 reports
-
Escape the url parameter before inserting it into the DOM.
Seen in 2 reports
-
Filter after the final decoding step rather than before a second decode.
-
HTML-encode filenames before inserting them into directory listings.
-
HTML-encode report parameters before rendering them.
Seen in 2 reports
-
HTML-encode user values inserted into email bodies.
-
Make sure CSP applies to Blob URLs and to pages that load third-party scripts.
Seen in 2 reports
-
Normalise cookie names consistently between browser and server and avoid disclosing cookies in errors.
-
Output-encode the search query in results pages.
-
Redirect targets should be validated as http(s) URLs on the trusted host before assignment.
-
Reject javascript: and data: schemes in integration base URL fields.
Seen in 2 reports
-
Require CSRF tokens and the X-Requested-With header on state-changing requests such as adding favourites or logging in.
-
Sanitise and encode the returnUrl parameter and username value before inserting them into the DOM.
Seen in 2 reports
-
Medium -
Medium
-
-
Sanitise and encode user input before including it in email HTML.
Seen in 2 reports
-
Sanitise chat messages server-side and output-encode them before rendering.
-
Sanitise embedded markup in editor paste handling and restrict data: URL image sources.
Seen in 2 reports
-
Sanitise HTML in diagram labels and syntax before inserting rendered Mermaid diagrams into the page.
Seen in 2 reports
-
Sanitise SVG uploads or restrict script content in them, as with profile picture uploads.