Documentation
¶
Overview ¶
Package pii finds personal data in response bodies and headers before they are written as public (into git). It looks for e-mail addresses, phone numbers, Serbian personal numbers (JMBG), payment card numbers and IBANs; numbers are checked against their checksum to keep false alarms rare. Texts are also read URL-decoded, with HTML entities resolved and with base64 runs decoded. Findings never carry the full value.
Index ¶
- Constants
- Variables
- func Kind(k string) bool
- func Mask(s string) string
- type Detector
- func (d *Detector) Allowed(s string) bool
- func (d *Detector) Headers(h [][2]string) ([]Finding, [][2]string)
- func (d *Detector) Scan(body []byte) []Finding
- func (d *Detector) ScanResponse(body []byte) []Finding
- func (d *Detector) ScanText(where, text string) []Finding
- func (d *Detector) Spans(s string) []Span
- type Finding
- type Span
Constants ¶
const Credential = "credential"
Credential is the kind of a credential ScanResponse finds.
Variables ¶
var Kinds = []string{"email", "phone", "jmbg", "card", "iban"}
Kinds are the kinds of personal data a Detector finds.
Functions ¶
Types ¶
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
Detector finds personal data, except values matching an allow pattern.
func (*Detector) Allowed ¶
Allowed reports whether s matches an allow pattern: a value the project declared not personal.
func (*Detector) Headers ¶
Headers finds personal data in header values (a Location with an e-mail address, a Content-Disposition with a JMBG in the file name). It returns the findings and the headers with that data hidden, letters as x and digits as 0 (the whole value when only a decoded form held it), so the record that goes into git does not hold it either. h is not changed.
func (*Detector) Scan ¶
Scan looks at every string in a JSON body (keys included) and at its integers, or at the whole body when it is not JSON. It walks the body without building it (jsonx.Walk): the tree of a body of a few megabytes would take many times that. The texts it reads are views of body, not copies (a body read off the heap stays there); findings copy what they keep.
func (*Detector) ScanResponse ¶
ScanResponse is Scan for a response body that would be stored in git: it also finds credentials (kind "credential"), which must not be committed either. In JSON: a JWT anywhere, a string under a key named as a credential (access_token, csrf, api_key, signature) that is shaped like one, also as the value of an object whose name says so ({"name":"api_key","value":…}, AWS's Key and Value), and a URL with a credential in its query or fragment (a signed or presigned URL, a link with its token). In another body, see ScanText.
func (*Detector) ScanText ¶
ScanText is ScanResponse for a text that is not JSON, such as a part of a document; where names it in the findings. Its credentials are a JWT, a URL with one in its query or fragment, and in a form body (access_token=…&token_type=bearer) or in XML a pair, element or attribute named as a credential that is shaped like one.