From e8b79478b1807b8f8828c51e989d83c5ae7d6d89 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Mon, 13 Jul 2020 23:33:32 -0400 Subject: Initial commit --- csp/csp.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 csp/csp.go (limited to 'csp') diff --git a/csp/csp.go b/csp/csp.go new file mode 100644 index 0000000..15fc1ca --- /dev/null +++ b/csp/csp.go @@ -0,0 +1,33 @@ +package csp + +import ( + "encoding/json" + "io" +) + +type Report struct { + BlockedURI string `json:"blocked-uri"` + Disposition string `json:"disposition"` + DocumentURI string `json:"document-uri"` + EffectiveDirective string `json:"effective-directive"` + OriginalPolicy string `json:"original-policy"` + Referrer string `json:"referrer"` + ScriptSample string `json:"script-sample"` + StatusCode int `json:"status-code"` + ViolatedDirective string `json:"violated-directive"` + SourceFile string `json:"source-file"` + LineNumber int `json:"line-number"` + ColumnNumber int `json:"column-number"` +} + +func ReadReport(r io.Reader) (*Report, error) { + type body struct { + Report Report `json:"csp-report"` + } + d := json.NewDecoder(r) + var b body + if err := d.Decode(&b); err != nil { + return nil, err + } + return &b.Report, nil +} -- cgit v1.2.3