Skip to content

Instantly share code, notes, and snippets.

@srquinn21
Last active August 28, 2020 02:04
Show Gist options
  • Select an option

  • Save srquinn21/3432e6c793a4277dfd830f40d9ee425d to your computer and use it in GitHub Desktop.

Select an option

Save srquinn21/3432e6c793a4277dfd830f40d9ee425d to your computer and use it in GitHub Desktop.

Revisions

  1. srquinn21 revised this gist Jan 31, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.markdown
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,4 @@ https://www.notsosecure.com/how-cross-site-websocket-hijacking-could-lead-to-ful

    **TL;DR**: Websockets, by spec, do not respect the browser's Same Origin Policy enforced for CORs and XHR requests. This means that a connection made in one browser tab can be hijacked in another browser tab similar to a typical XSS attack. In order to protect our services, we need to make sure that the Origin header matches the application's server name.

    I've provided a nginx.conf file below that demonstrates how to check the Origin header. In addition to this config update, you'll also want to be sure to use a session token during your websocket handshake that is verified on the server for each connection.
    I've provided a nginx.conf file below that demonstrates how to check the Origin header. In addition to this config update, you'll also want to be sure to use a session token during your websocket handshake that is verified on the server for each connection. I suggest looking into JSON Web Tokens (JWT)
  2. srquinn21 revised this gist Jan 31, 2018. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.markdown
    Original file line number Diff line number Diff line change
    @@ -4,4 +4,6 @@ While researching possible Websocket vulnerabilities, I came across the "Cross S
    http://www.christian-schneider.net/CrossSiteWebSocketHijacking.html
    https://www.notsosecure.com/how-cross-site-websocket-hijacking-could-lead-to-full-session-compromise/

    TL;DR: Websockets, by spec, do not respect the browser's Same Origin Policy enforced for CORs and XHR requests. This means that a connection made in one browser tab can be hijacked in another browser tab similar to a typical XSS attack. In order to protect our services, we need to make sure that the Origin header matches the application's hostname.
    **TL;DR**: Websockets, by spec, do not respect the browser's Same Origin Policy enforced for CORs and XHR requests. This means that a connection made in one browser tab can be hijacked in another browser tab similar to a typical XSS attack. In order to protect our services, we need to make sure that the Origin header matches the application's server name.

    I've provided a nginx.conf file below that demonstrates how to check the Origin header. In addition to this config update, you'll also want to be sure to use a session token during your websocket handshake that is verified on the server for each connection.
  3. srquinn21 revised this gist Jan 31, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.markdown
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    ### Notes
    While researching possible Websocket vulnerabilities, I came across the "Cross Site WebSocket Hijacking" attack as documented here:

    http://www.christian-schneider.net/CrossSiteWebSocketHijacking.html
    http://www.christian-schneider.net/CrossSiteWebSocketHijacking.html
    https://www.notsosecure.com/how-cross-site-websocket-hijacking-could-lead-to-full-session-compromise/

    TL;DR: Websockets, by spec, do not respect the browser's Same Origin Policy enforced for CORs and XHR requests. This means that a connection made in one browser tab can be hijacked in another browser tab similar to a typical XSS attack. In order to protect our services, we need to make sure that the Origin header matches the application's hostname.
  4. srquinn21 renamed this gist Jan 31, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md → README.markdown
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ###Notes
    ### Notes
    While researching possible Websocket vulnerabilities, I came across the "Cross Site WebSocket Hijacking" attack as documented here:

    http://www.christian-schneider.net/CrossSiteWebSocketHijacking.html
  5. srquinn21 revised this gist Jan 31, 2018. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    ###Notes
    While researching possible Websocket vulnerabilities, I came across the "Cross Site WebSocket Hijacking" attack as documented here:

    http://www.christian-schneider.net/CrossSiteWebSocketHijacking.html
    https://www.notsosecure.com/how-cross-site-websocket-hijacking-could-lead-to-full-session-compromise/

    TL;DR: Websockets, by spec, do not respect the browser's Same Origin Policy enforced for CORs and XHR requests. This means that a connection made in one browser tab can be hijacked in another browser tab similar to a typical XSS attack. In order to protect our services, we need to make sure that the Origin header matches the application's hostname.
  6. srquinn21 renamed this gist Jan 31, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. srquinn21 created this gist Jan 31, 2018.
    22 changes: 22 additions & 0 deletions conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    # DENY all requests by default (PoLP)
    set $websocket_same_origin_policy "DENY";
    # ALLOW non-browser clients
    if ($http_origin = "") {
    set $websocket_same_origin_policy "ALLOW";
    }
    # ALLOW browsers with matching Origin header and ServerName
    # (only browsers reliably set a truthful Origin header)
    if ($http_origin = $scheme://$server_name) {
    set $websocket_same_origin_policy "ALLOW";
    }

    location /ws {
    # DENY any request that violates the Same Origin Policy
    if ($websocket_same_origin_policy != "ALLOW") {
    return 403;
    }
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass http://localhost:3030;
    }