Commit 2e3e05a9 authored by Nicolas Pernoud's avatar Nicolas Pernoud
Browse files

fix: web security middleware compatibility with web sockets

parent 2cd0f5e8
Pipeline #4853 passed with stages
in 2 minutes and 35 seconds
package middlewares
import (
"bufio"
"errors"
"fmt"
"net"
"net/http"
"strconv"
"strings"
......@@ -47,7 +50,7 @@ func (s webSecurityWriter) WriteHeader(code int) {
cspHeader = cspHeader + fmt.Sprintf("; frame-ancestors %v", s.source)
}
} else { // If not, forge a default CSP Header
cspHeader = fmt.Sprintf("default-src %[1]v 'self'; img-src %[1]v blob: 'self'; script-src 'self' %[1]v %[2]v; style-src 'self' 'unsafe-inline'; frame-src %[1]v; frame-ancestors %[1]v", s.source, inline)
cspHeader = fmt.Sprintf("default-src %[1]v 'self'; img-src %[1]v 'self' blob: ; script-src 'self' %[1]v %[2]v; style-src 'self' 'unsafe-inline'; frame-src http: %[1]v; frame-ancestors %[1]v", s.source, inline)
}
// Set the resulting CSP Header
s.w.Header().Set("Content-Security-Policy", cspHeader)
......@@ -68,6 +71,14 @@ func (s webSecurityWriter) Header() http.Header {
return s.w.Header()
}
func (s webSecurityWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
hj, ok := s.w.(http.Hijacker)
if !ok {
return nil, nil, errors.New("response writer is not an hijacker")
}
return hj.Hijack()
}
// WebSecurity adds good practices security headers on http responses
func WebSecurity(next http.Handler, source string, allowEvalInlineScript bool) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
......
......@@ -2,115 +2,115 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin: auto; background: rgba(0, 0, 0, 0) none repeat scroll 0% 0%; display: block; shape-rendering: auto;" width="300px" height="300px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid">
<g transform="translate(80,50)">
<g transform="rotate(0)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="1">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="1">
<animateTransform attributeName="transform" type="scale" begin="-1.171875s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-1.171875s"></animate>
</circle>
</g>
</g><g transform="translate(77.7163859753386,61.48050297095269)">
<g transform="rotate(22.5)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.9375">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.9375">
<animateTransform attributeName="transform" type="scale" begin="-1.09375s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-1.09375s"></animate>
</circle>
</g>
</g><g transform="translate(71.21320343559643,71.21320343559643)">
<g transform="rotate(45)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.875">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.875">
<animateTransform attributeName="transform" type="scale" begin="-1.015625s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-1.015625s"></animate>
</circle>
</g>
</g><g transform="translate(61.4805029709527,77.7163859753386)">
<g transform="rotate(67.5)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.8125">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.8125">
<animateTransform attributeName="transform" type="scale" begin="-0.9375s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-0.9375s"></animate>
</circle>
</g>
</g><g transform="translate(50,80)">
<g transform="rotate(90)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.75">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.75">
<animateTransform attributeName="transform" type="scale" begin="-0.859375s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-0.859375s"></animate>
</circle>
</g>
</g><g transform="translate(38.51949702904731,77.7163859753386)">
<g transform="rotate(112.5)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.6875">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.6875">
<animateTransform attributeName="transform" type="scale" begin="-0.78125s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-0.78125s"></animate>
</circle>
</g>
</g><g transform="translate(28.786796564403577,71.21320343559643)">
<g transform="rotate(135)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.625">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.625">
<animateTransform attributeName="transform" type="scale" begin="-0.703125s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-0.703125s"></animate>
</circle>
</g>
</g><g transform="translate(22.283614024661397,61.4805029709527)">
<g transform="rotate(157.5)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.5625">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.5625">
<animateTransform attributeName="transform" type="scale" begin="-0.625s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-0.625s"></animate>
</circle>
</g>
</g><g transform="translate(20,50.00000000000001)">
<g transform="rotate(180)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.5">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.5">
<animateTransform attributeName="transform" type="scale" begin="-0.546875s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-0.546875s"></animate>
</circle>
</g>
</g><g transform="translate(22.283614024661393,38.51949702904731)">
<g transform="rotate(202.49999999999997)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.4375">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.4375">
<animateTransform attributeName="transform" type="scale" begin="-0.46875s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-0.46875s"></animate>
</circle>
</g>
</g><g transform="translate(28.78679656440357,28.786796564403577)">
<g transform="rotate(225)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.375">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.375">
<animateTransform attributeName="transform" type="scale" begin="-0.390625s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-0.390625s"></animate>
</circle>
</g>
</g><g transform="translate(38.51949702904729,22.283614024661404)">
<g transform="rotate(247.49999999999997)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.3125">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.3125">
<animateTransform attributeName="transform" type="scale" begin="-0.3125s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-0.3125s"></animate>
</circle>
</g>
</g><g transform="translate(49.99999999999999,20)">
<g transform="rotate(270)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.25">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.25">
<animateTransform attributeName="transform" type="scale" begin="-0.234375s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-0.234375s"></animate>
</circle>
</g>
</g><g transform="translate(61.4805029709527,22.2836140246614)">
<g transform="rotate(292.50000000000006)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.1875">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.1875">
<animateTransform attributeName="transform" type="scale" begin="-0.15625s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-0.15625s"></animate>
</circle>
</g>
</g><g transform="translate(71.21320343559643,28.78679656440357)">
<g transform="rotate(315)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.125">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.125">
<animateTransform attributeName="transform" type="scale" begin="-0.078125s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="-0.078125s"></animate>
</circle>
</g>
</g><g transform="translate(77.7163859753386,38.51949702904729)">
<g transform="rotate(337.49999999999994)">
<circle cx="0" cy="0" r="3" fill="#0d47a1" fill-opacity="0.0625">
<circle cx="0" cy="0" r="1.5" fill="#0d47a1" fill-opacity="0.0625">
<animateTransform attributeName="transform" type="scale" begin="0s" values="2 2;1 1" keyTimes="0;1" dur="1.25s" repeatCount="indefinite"></animateTransform>
<animate attributeName="fill-opacity" keyTimes="0;1" dur="1.25s" repeatCount="indefinite" values="1;0" begin="0s"></animate>
</circle>
</g>
</g>
<!-- [ldio] generated by https://loading.io/ --></svg>
\ No newline at end of file
</svg>
\ No newline at end of file
......@@ -42,7 +42,7 @@
</div>
<div class="navbar-menu">
<div class="navbar-end">
<div class="navbar-item"><p>v4.3.5</p></div>
<div class="navbar-item"><p>v4.3.6</p></div>
</div>
</div>
</nav>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment