XSS
Attacks andCSRF
attack
1.XSS
attack
1. The concept
XSS (Cross Site Scripting) : Cross-domain Scripting attacks
Principle 2.
You don’t need to do any login authentication, it will inject scripts (js, HMTL code blocks, etc.) into your page through legitimate actions (such as typing in the URL, in the comment box).
3. To prevent
- Coding; Encode user input.
- Filtering; Removes attributes related to user input and events. (filter
script
,style
,iframe
Such as node) - Correction; use
DOM Parse
Convert, correct unpairedDOM
The label. HttpOnly
.
Classification of 4.
- Reflective (non-persistent) : Click the link to execute the script
- Storage (persistent) : Malicious input saves the database, other users access, execute scripts
- Based on the
DOM
: Malicious modificationDOM
Structure, based on the client
2,CSRF
attack
1. The concept
Cross-site Request Forgery (SRF) : Cross-site request forgery.
Principle 2.
- Log on to trusted sites
A
And generate it locallyCookie
. (If the user is not logged in to the siteA
, so the websiteB
At the time of induction, request the siteA
的api
Interface, will prompt you to log in). - Without logout
A
In the case of visiting dangerous websitesB
(Actually using the websiteA
“).
3. To prevent
token
Validation;- Hide the token; the
token
Hidden in thehttp
The request ofhead
In the. referer
Validation; Verify the page source.
3. The difference between the two
CSRF
: You need to log in to the website firstA
To obtaincookie
.XSS
: No login is required.CSRF
: Use the websiteA
The vulnerability itself, to request the siteA
的api
.XSS
: Is to the websiteA
injectionJS
Code, and then executeJS
To tamper with the websiteA
The content of the.