2025년 7월 1일 화요일

Segfault ethical hacking week 11-2

 

Understanding XSS (Cross-Site Scripting): A Deep Dive


1. Overview of XSS Mitigation Strategies

Including an overview table at the beginning helps readers quickly grasp the main concepts. For example:

CategoryMethodAdvantagesDisadvantages
Blacklist Filtering Block specific strings/patterns              Flexible        Easy to bypass
Whitelist Filtering  Allow only specific strings/tags           Very secure    Highly restricts user input
HTML Entity Encoding    Escape special charactersPrevents script execution       Limits input freedom


2. Concrete HTML Entity Encoding Examples

Adding a reference table makes this more intuitive:

CharacterEntity
<&lt;
>&gt;
&&amp;
"&quot;
'&#x27;
/&#x2F;


3. Event Handler Reference

list of common event handler attributes is especially important for beginners. You can organize them in a table:

EventDescription
onerrorExecutes on resource load failure
onloadExecutes when loading is complete
onclickExecutes on click
onmouseoverExecutes on mouse over
onfocusExecutes when an element gains focus
onblurExecutes when an element loses focus

There are over 50 different event attributes, so in whitelist filtering, you should explicitly allow only those that are strictly necessary.


4. Introducing Content Security Policy (CSP)

Recently, CSP configuration has become a core part of XSS defense. A brief overview is helpful:

  • What is CSP?

    • A security policy that instructs the browser which resources are allowed to load.

  • Example HTTP Header

    Content-Security-Policy: default-src 'self'; script-src 'self';
    • default-src 'self': Only allow resources from your own domain.

    • script-src 'self': Block external scripts.

  • Advantages

    • Blocks script injection effectively.

  • Disadvantages

    • Can be disruptive when retrofitted to existing services.

Adding this section will improve the professional credibility of your article.


5. HTTP Only / Secure Cookie Flags

It’s also worth mentioning cookie protection settings that are frequently discussed alongside XSS mitigation:

  • HttpOnly: Prevents JavaScript from accessing cookies.

  • Secure: Sends cookies only over HTTPS.

  • SameSite: Restricts cross-site request cookies.

Example:

Set-Cookie: session=...; HttpOnly; Secure; SameSite=Strict


6. Brief Introduction to DOM-based XSS

Most examples you shared are Reflected or Stored XSS. It helps to briefly introduce DOM-based XSS as well:

  • What is DOM-based XSS?

    • Occurs when client-side scripts process untrusted input (e.g., locationdocument.write) without sanitization.

  • Example

    var q = location.hash.substr(1); document.getElementById("result").innerHTML = q;

    → If you navigate to #<img src=x onerror=alert(1)>, the script executes.

댓글 없음:

댓글 쓰기

Segfault ethical hacking week 16

Who Are You, and What Can You Do? (Authentication & Authorization Vulnerabilities) It's hard to imagine a web service without a logi...