MODULE 06 · AUTHENTICATION & SECURITY

XSS

Cross-site scripting is an injection vulnerability in which untrusted content is interpreted as script in a user's trusted browser context.

01 · What is it?

XSS happens when an application places attacker-controlled input into a page without safely handling it, allowing code to run in another user's browser.

The browser trusts the page's origin, so injected script may access what that page can access.

02 · Think of it like...

Think of XSS like printing a visitor's unverified note directly onto an official noticeboard as if it were the board's own instruction.

Readers trust the board, so the note gains the board's authority.

Untrusted Input→Page Rendering→Trusted Origin→Script Execution

03 · What does it do?

XSS can change what users see, capture input, or perform actions available to the page.

Inject Markup

Place unexpected HTML or script into rendered content.

Run in Context

Execute with the permissions of the trusted page.

Read Page Data

Access page content available to the script.

Perform Actions

Trigger page actions as the user when controls allow it.

04 · Where is it used?

XSS risk appears anywhere untrusted data is rendered into a browser page.

Comments

User posts are displayed to other visitors.

Search Results

Query text is reflected into a page.

Rich Text

Formatted content is accepted from users.

Templates

Server or client templates combine data and markup.

05 · Example

const name = userInput;
message.innerHTML = `Hello ${name}`;

If userInput is not trusted and safely handled, inserting it with innerHTML can turn data into markup or script. Text rendering or a trusted sanitizer is safer.

06 · How it connects

User Input→Storage or Response→Unsafe Rendering→Browser Executes Content

07 · Do Not Confuse

XSS

Untrusted content becomes executable in a trusted browser context.

CSRF

A browser is tricked into sending an unwanted authenticated request.

SQL Injection

Untrusted input changes the meaning of a database query.

08 · Topic Glossary

ENGLISH TERM中文SIMPLE ENGLISH中文小白理解
XSS跨站脚本攻击An attack that makes untrusted content run as script in a web page.让不可信内容在网页中被当作脚本执行的攻击。
Input输入Data supplied by a user or another system.用户或其他系统提供给应用的数据。
Escaping转义Encoding special characters so they remain text.把特殊字符编码成普通文字,避免被当成代码。
Sanitization清理Removing or safely transforming dangerous content.删除或安全处理可能有害的内容。

09 · What to Remember

XSS occurs when untrusted data is allowed to become executable content in a trusted page.

Use context-aware output encoding, safe DOM APIs, carefully configured sanitization, and a strong Content Security Policy.