XSS is what?

Cross-site scripting (also known as XSS) is a malicious attempt to steal information from users using a vulnerability in a website.

There are several common ways of attacking XSS:

  • reflective


  • Dom-Based   


<input type="text" id="web" /><button id="add"</button> <div class="box"></div>


$('box').html(`<img src="${$('#web').val()}"/> ') // For example, I typed: XXX" onerror="alert(1) => 
<img src="XXX" onerror="alert(1)" />Copy the code

  • Persistent attack


Ways to avoid XSS attacks:

  • Reflection type:



Solution: Filter parameters, encodeURIComponent(‘ path parameters ‘)

  • Dome_Based:

It’s called the XSS payload.


Solution: Escape the input

$('box').html(`<img src="${encodeURI($('#web').val())}"/ > `)Copy the code

  • Persistent attack

This type of attack, commonly known as “XSS storage”, is where malicious scripts are stored on the server and can be accessed by anyone, with a greater scope than reflex or dome-based attacks


Solution:

  1. Verification is required before the client sends the packet to the server
  2. The server is doing a filter
  3. Filter directly on input

Conclusion:

Escape + filter