Search
English

How XSS attacks slip malicious scripts into user input, and basic defenses(qiita.com)

startupxo Discuss

Writing language: KoreanRead in the original language

Summary / Read source ↗

- XSS is an attack that runs malicious scripts made by an attacker in other users' browsers. A script is a small program that makes a web page move. The source explains that just opening a malicious link or viewing a compromised page can make it run with the site's permissions. - The source divides XSS into reflected, stored, and DOM-based types. Reflected and stored XSS happen when the server builds dangerous HTML and sends it back. DOM-based XSS happens when the server sends only normal HTML and the browser's script inserts a URL value into the page, so server-side escaping is hard to rely on to block it. - The basic defense is to insert user input with textContent instead of innerHTML, so it is displayed only as text. The source also introduces Sanitizer APIs such as setHTML(). Citing web.dev material, it says Firefox supports them from 148 (2026 February), Chrome and Edge from 146, and Safari does not support them. - HttpOnly cookies stop scripts from reading cookies, which reduces the risk of session information theft. However, they do not stop script execution itself. CSP restricts execution of scripts that are not allowed, but the source says it has trade-offs: setting up external service integrations is troublesome and pages can easily break.
Found on

Qiita ↗ / Published by source

Have you run into something like this? Tell us in a line or two what you did. You do not need to know the product.

Sign in to comment

1 comment

Editorial opinionstartupxo

O: Frontend developers may want to look for places in their own pages where user input or URL values are inserted with innerHTML, and switch to textContent where the content only needs to display text. X: The setHTML() method of the Sanitizer API is based on browser support as of late October 2026, so in environments where Safari does not support it, DOMPurify should be used instead.
Writing language: Korean

Keyboard shortcuts

Choose a post with J and K or the arrow keys, then press Enter.

K ↑ / J ↓
Previous post / next post
Enter C
Open summary and comments for the selected post
O
Open the original link of the selected post
/
Search
?
Show this help
Tab
Move to the submit or comment button, then press Enter

Type normally in text fields. Tab and Enter are always available.