flawopen.com/xss/Rust
Learn how to fix Cross-Site Scripting (XSS) (CWE-79) in Rust. Side-by-side vulnerable vs secure code examples for Askama, Tera auto-escaping, and Actix-web HTML rendering.
공용 게시판에 '이 글을 읽는 즉시 옆 사람에게 지갑을 건네주시오'라는 메모를 붙여놓는 상황을 비유해 보겠습니다. 방문객들이 게시판에 붙은 메모의 지시를 무조건 따른다면, 악의적인 메모를 붙인 누구나 사람들의 돈을 훔칠 수 있게 됩니다.
Web Application SecurityCWE-79.CWE-79CWE-79): Standard Common Weakness Enumeration classification for xss-rust.Defense-in-Depth공격자가 폼 입력창이나 URL 매개변수에 HTML 태그 또는 JavaScript(예: <script> 또는 <img onerror=...>)를 삽입합니다.
웹 애플리케이션이 입력을 적절한 HTML 엔티티로 변환하지 않고 원시 문자열 그대로 페이지에 반영합니다.
피해자가 웹 페이지를 방문하면 브라우저가 주입된 코드를 실행 가능한 스크립트로 인식하여 실행합니다.
스크립트가 피해자의 세션 권한으로 실행되어 인증 쿠키와 로컬 스토리지 토큰을 탈취합니다.
// format! has no HTML awareness
let body = format!(
"<div>Welcome, {}</div>", name
);
// Askama auto-escapes .html templates
#[derive(Template)]
#[template(path = "welcome.html")]
struct Welcome<'a> { name: &'a str }
// welcome.html: <div>Welcome, {{ name }}</div>