Where the flaw comes from

Cross-site scripting (XSS) occurs when a site places untrusted data into a page in a way that the browser treats as code. Affected input can come from comments, profile fields, search terms or external content.

The impact depends on the page and user. A flaw can expose information available to the victim or allow unwanted actions in the application.

Encode output for the exact context

Use a template engine that escapes output by default. Keep data as text when the page does not need HTML. If rich text is required, use a maintained allowlist sanitizer.

Avoid building HTML or script strings from user input. Validate URLs and do not insert untrusted values into event handlers or script blocks.

Test stored and reflected input

Check content that appears immediately and content saved for another user to view. Test search, comments, account settings and imported data.

Use browser protections as an extra layer. They do not replace correct output encoding and input handling in the application.