Web Security

Going to quote these lines in any #tradeoff discussions going forward:

Would you like the strongest encryption algo in world? Yes.
Would you like logins to take ten minutes? No.
- @stevekinney in @FrontendMasters course on web security

— Ankit Kashyap (@ankitwww) February 8, 2025

the most secured systems are the ones people don't want to use.

In security world, perfect is many times opposite of good.

Cookies

Session Hijacking


Cross-site request forgery

A vulnerability that allows an attacker to make unauthorized requests in the user's behalf.

Pasted image 20250208183101.png

Pasted image 20250208183248.png

3 Ingredients to the CSRF

Pasted image 20250208183519.png

Pasted image 20250208183759.png

CSRF fixes

SameSite Cookie and CSRF

{0BCD6240-B503-458D-B0E0-CCE8FBAF0739}.png

SameSite:Lax is default these days
SameSite:None is irresponsible

SameSite=Strict:

Pasted image 20250208191009.png

Pasted image 20250208191226.png

Pasted image 20250208191412.png
Pasted image 20250208191505.png

Always remember, CSRF does not need to come from javascript - it can be in CSS too (like background url as get request endpoint)

Pasted image 20250208194505.png

{5E9F4FFB-E672-4E22-A0E2-B29517EB29B1}.png

Pasted image 20250208194910.png

Like - deleting github repor - lots of back and forth and minimizing CSRF.

CORS: Origin + Methods + Header +

Pasted image 20250208224639.png

{469A0F36-6BBA-4728-9D8A-A995A8709F5B}.png


Cross-Site Scripting

This is coming from your own house!
XSS - The Samy worm 2005

{C67D3042-F898-46A3-A8B2-538B3E5BA02E}.png

{DCEBC287-581A-4DF5-AE16-1E9194F5A920}.png

Pasted image 20250208233915.png

React and XSS

https://github.com/payloadbox/xss-payload-list

Pasted image 20250208235137.png

Content Security Policy

Pasted image 20250208235627.png

CSP can be thought of a second layer defense.

{75AE9D92-942D-4363-ABF8-A577246107EE}.png
Pasted image 20250208235951.png

Pasted image 20250209001411.png

NONCE

If you need inline script or css loading . Bit like CSRF.

Pasted image 20250209193038.png

Pasted image 20250209193305.png


Original Slides from Steve Kinney course

![[Web_Security.pdf]]

if above not working - https://drive.google.com/file/d/1UiGq-Ok7Z-ak4lBR7yH9YEAPnFeqvM9i/view?usp=sharing