flawopen.com/xss/Csharp
Learn how to fix Cross-Site Scripting (XSS) (CWE-79) in C# / .NET. Side-by-side vulnerable vs secure code examples for Razor Html.Raw hazards and AntiXssEncoder.
想象一下,有人在社区公告栏上贴了一张便签:'凡阅读此便签者,请立刻将钱包交给身旁的人'。如果路过的居民盲目执行公告栏上的每一条纸条指令,任何张贴便签的人都能瞬间偷走所有人的财物。
Web Application SecurityCWE-79.CWE-79CWE-79):Standard Common Weakness Enumeration classification for xss-csharp.Defense-in-Depth攻击者在表单输入框、URL 查询参数中输入恶意 HTML 标签或 JavaScript 代码(如 <script> 或 <img onerror=...>)。
应用程序将原始输入未经上下文 HTML 实体编码即直接拼接入页面或写入数据库。
当受害者访问该页面时,浏览器将未转义的字符解析为合法的可执行脚本而非普通文本。
恶意脚本在受害者会话上下文中执行,窃取 document.cookie、读取 LocalStorage 凭据或冒名发起操作。
@* Html.Raw skips encoding entirely *@
<div>
Welcome, @Html.Raw(Model.Name)
</div>
@* default Razor output auto-encodes *@
<div>
Welcome, @Model.Name
</div>
Html.Raw() for untrusted data。