Xiangxiang's Personal Site

Machine Learning & Security Engineer
生命不息,折腾不止,留下一点活着的记录.

View on GitHub
18 February 2018

Web安全蓝图

by xiangxiang

从Web发展的历史看安全

Part 1: HTTP basics

1. HTTP request header format

VERB /resource/locator HTTP/1.1
Header1:Value1
Header2:Value2
...

<Body of request>

2. HTTP request headers

4. HTML: parsed according to the relevant spec(generally HTML5 now);

5. Same-Origin Policy: protocol+host+port

Part 2: Web security outline

1. Web 1.0

            HTTP 
client  <--------->  server
    |                   |
[browser]          [Web server]
    |                   | 
    |                   |
(private)            database 
   data

Attacks

2. Web 2.0

JavaScript cant read/write cookies & alter DOM -> Same-Origin Policy(SOP)

Attacks

Part 3: An Overview of HTTP Security Headers

1. Content-Security-Policy

directives explanation
default-src This acts as a catchall for everything else.
script-src Describes where we can load javascript files from
style-src Describes where we can load stylesheets from
img-src Describes where we can load images from
connect-src Applies to AJAX and Websockets
font-src Describes where we can load fonts from
script-src Describes where we can load javascript files from
object-src Describes where we can load objects from ()
media-src Describes where we can load audio and video files from
frame-ancestors Describes which sites can load this site in an iframe
source explanation
* Load resources from anywhere
‘none’ Block everything
‘self’ Can only load resources from same origin
data: Can only load resources from data schema (Base64)
something.example.com Can only load resources from specified domain
https: Can only load resources over HTTPS
‘unsafe-inline’ Allows inline elements (onclick, tags, javascript:,)
‘unsafe-eval’ Allows dynamic code evaluation (eval() function)
‘sha256-‘ Can only load resources if it matches the hash
‘nonce-‘ Allows an inline script or CSS to execute if the script tag contains a nonce attribute matching the nonce specifed in the CSP header.

2. Strict-Transport-Security

3. X-Frame-Options

4. X-XSS-Protection

5. X-Content-Type-Options

6. CORS

实际中选择一个好的框架(secure by default),按照文档好好学习。

参考链接

  1. An Overview of HTTP Security Headers
  2. What is the difference between CORS and CSPs
  3. Content Security Policy (CSP) Bypasses
tags: web security