(A3) Injection - Cross Site Scripting (Mitigation) - Webgoat

1. Reflective XSS

  • Ngăn chặn XSS sử dụng escaping
  • Ta cập nhật lại đoạn code mẫu đề bài cho như sau và nhấn submit là xong:
<%@taglib prefix="e" uri="https://www.owasp.org/index.php/OWASP_Java_Encoder_Project" %> <html>
<html>
<head>
    <title>Using GET and POST Method to Read Form Data</title>
</head>
<body>
    <h1>Using POST Method to Read Form Data</h1>
    <table>
        <tbody>
            <tr>
                <td><b>First Name:</b></td>
                <td>${e:forHtml(param.first_name)}</td>
            </tr>
            <tr>
                <td><b>Last Name:</b></td>
                <td>${e:forHtml(param.last_name)}</td>
            </tr>
        </tbody>
    </table>
</body>
</html>

alt

2. Stored XSS

  • Một cách để ngăn chặn XSS Store là sử dụng OWASP AntiSamy. AntiSamy có thể tạo "clean" string dựa trên tệp chính sách có thể điều chỉnh.
  • Ta cập nhật lại đoạn code mẫu đề bài cho như sau và nhấn submit là xong:
import org.owasp.validator.html.*;
import MyCommentDAO;

public class AntiSamyController {
    public void saveNewComment(int threadID, int userID, String newComment){
        Policy policy = Policy.getInstance("antisamy-slashdot.xml");
        AntiSamy as = new AntiSamy();
        CleanResults cr = as.scan(newComment, policy);
        MyCommentDAO.addComment(threadID, userID, cr.getCleanHTML());
    }
}

alt

Cảm ơn bạn đã đọc bài viết ! 🥰 🥰 🥰

Hãy nêu ý kiến của mình ở phần bình luận phía dưới nhé !

✨ Bài viết liên quan

(A3) Injection - Cross Site Scripting (Stored) - Webgoat 🐐 Bài viết này mình sẽ hướng dẫn các bạn làm phần (A3) Injection - Cross Site Scripting (Stored)

Made by @thevi31415

© 2024 Nguyen Duong The Vi. All Rights Reserved.