Skip to content

Instantly share code, notes, and snippets.

@avin
Last active March 10, 2023 09:39
Show Gist options
  • Select an option

  • Save avin/fa5d8aa6e839c7fb2c18b695b355140c to your computer and use it in GitHub Desktop.

Select an option

Save avin/fa5d8aa6e839c7fb2c18b695b355140c to your computer and use it in GitHub Desktop.
codebashing courses summary

Reverse Tabnabbing

If tag with target="_blank" or uses window.open the hacker can replace original tab with opener.location="https://www.evilsite.com"; by opened page. It can be used in a phishing attack To fix it add rel="noopener" to and 'noopener' as third argument for window.open(: window.open('https://www.your.url','_blank','noopener')

HTTP Strict-Transport-Security (HSTS)

Add header Strict-Transport-Security: max-age=31536000; includeSubdomains; preload to make sure that the user once accessed the HTTPS version of the page will always be automatically redirected to it bypassing requests for HTTP.

No Server-Side Validation

Duplicate client and server validations. Do not leave only client validations. Hacker can exploit it with proxy applications (ZAP, Burp Suit etc).

Clickjacking

Draw website in iframe with opacity 0 as overlay. Place an iframe so that the user clicks on something inside the iframe, thinking that he is clicking on something on the main site. To protect use X-Frame-Options or Content-Security-Policy headers specifying which sites can put the site in an iframe

Cross Site Request Forgery (CSRF)

Hacker sends request to legit site to change somethig, the request succeeds because the authorization cookie automatically goes with the request. Protect:

  • Use Synchronizer token (also called Anti-CSRF or CSRF token) manually sending (not by cookie)
  • Do not use HEAD and GET requests to change data.

Vulnerable and Outdated Components

Update buggy outdated libs that can be vurn for XSS

DOM XSS in URL

String from query params uses as HTML in page and may execute JS. Prevent by escape it before insert to HTML.

Secure:

  • Escape user input.
  • HTTPOnly cookie flag
  • Content Security Policy HTTP Header
  • X-XSS-Protection HTTP Header

DOM XSS in AJAX

Escape data before insert as HTML

DOM XSS in eval()

Do not use eval to parse JSON

Secure Cookie Flag

Use Secure flag for cookies to make sure it will be transfered by HTTPS and not HTTP to prevent sniffing.

HttpOnly Cookie Flag

Use HttpOnly flag for SessionID cookies to make sure JS will not read it, so XSS vulnerables will not allowed to steal user session.

DOM Open Redirect

https://example.com/redirect.php?url=https://attacker.com

Reflected XSS

Same as DOM XSS in URL.

Stored (Persistent) XSS

Saved XSS code on Server side (DB).

Cross-site Scripting (XSS) in React

Sanitize/Hardcode prefix for

  • iframe - src / srcdoc
  • a - href
  • form - action
  • object - data

The dangerouslySetInnerHTML Property

Sanitize content of dangerouslySetInnerHTML

Sensitive Data in Code

Use specialized software like SAST (Static Application Security Testing) to find security vulnerabilities in the application source code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment