aboutsummaryrefslogtreecommitdiff
path: root/csp
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2020-07-13 23:33:32 -0400
committerBen Burwell <ben@benburwell.com>2020-07-13 23:37:24 -0400
commite8b79478b1807b8f8828c51e989d83c5ae7d6d89 (patch)
tree5017c98ebc221bf8582def77e4dcdad005c16a71 /csp
Initial commit
Diffstat (limited to 'csp')
-rw-r--r--csp/csp.go33
1 files changed, 33 insertions, 0 deletions
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
+}