aboutsummaryrefslogtreecommitdiff
path: root/csp/csp.go
blob: 15fc1ca60875deeeab4f47b4c2f7b11457cbe791 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
}