XSSAttacks andCSRFattack

1.XSSattack

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

  1. Coding; Encode user input.
  2. Filtering; Removes attributes related to user input and events. (filterscript,style,iframeSuch as node)
  3. Correction; useDOM ParseConvert, correct unpairedDOMThe label.
  4. 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 theDOM: Malicious modificationDOMStructure, based on the client

2,CSRFattack

1. The concept

Cross-site Request Forgery (SRF) : Cross-site request forgery.

Principle 2.

  1. Log on to trusted sitesAAnd generate it locallyCookie. (If the user is not logged in to the siteA, so the websiteBAt the time of induction, request the siteAapiInterface, will prompt you to log in).
  2. Without logoutAIn the case of visiting dangerous websitesB(Actually using the websiteA“).

3. To prevent

  1. tokenValidation;
  2. Hide the token; thetokenHidden in thehttpThe request ofheadIn the.
  3. refererValidation; Verify the page source.

3. The difference between the two

  1. CSRF: You need to log in to the website firstATo obtaincookie.XSS: No login is required.
  2. CSRF: Use the websiteAThe vulnerability itself, to request the siteAapi.XSS: Is to the websiteAinjectionJSCode, and then executeJSTo tamper with the websiteAThe content of the.