parent
befb6bea22
commit
3baeec745c
18 changed files with 159 additions and 45 deletions
4
go.mod
4
go.mod
|
@ -80,7 +80,7 @@ require (
|
||||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||||
github.com/mattn/go-sqlite3 v1.14.8
|
github.com/mattn/go-sqlite3 v1.14.8
|
||||||
github.com/mholt/archiver/v3 v3.5.0
|
github.com/mholt/archiver/v3 v3.5.0
|
||||||
github.com/microcosm-cc/bluemonday v1.0.15
|
github.com/microcosm-cc/bluemonday v1.0.16
|
||||||
github.com/miekg/dns v1.1.43 // indirect
|
github.com/miekg/dns v1.1.43 // indirect
|
||||||
github.com/minio/md5-simd v1.1.2 // indirect
|
github.com/minio/md5-simd v1.1.2 // indirect
|
||||||
github.com/minio/minio-go/v7 v7.0.12
|
github.com/minio/minio-go/v7 v7.0.12
|
||||||
|
@ -125,7 +125,7 @@ require (
|
||||||
go.uber.org/multierr v1.7.0 // indirect
|
go.uber.org/multierr v1.7.0 // indirect
|
||||||
go.uber.org/zap v1.18.1 // indirect
|
go.uber.org/zap v1.18.1 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
|
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
|
golang.org/x/net v0.0.0-20211020060615-d418f374d309
|
||||||
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914
|
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
|
||||||
golang.org/x/text v0.3.6
|
golang.org/x/text v0.3.6
|
||||||
|
|
7
go.sum
7
go.sum
|
@ -868,8 +868,8 @@ github.com/mholt/acmez v0.1.3 h1:J7MmNIk4Qf9b8mAGqAh4XkNeowv3f1zW816yf4zt7Qk=
|
||||||
github.com/mholt/acmez v0.1.3/go.mod h1:8qnn8QA/Ewx8E3ZSsmscqsIjhhpxuy9vqdgbX2ceceM=
|
github.com/mholt/acmez v0.1.3/go.mod h1:8qnn8QA/Ewx8E3ZSsmscqsIjhhpxuy9vqdgbX2ceceM=
|
||||||
github.com/mholt/archiver/v3 v3.5.0 h1:nE8gZIrw66cu4osS/U7UW7YDuGMHssxKutU8IfWxwWE=
|
github.com/mholt/archiver/v3 v3.5.0 h1:nE8gZIrw66cu4osS/U7UW7YDuGMHssxKutU8IfWxwWE=
|
||||||
github.com/mholt/archiver/v3 v3.5.0/go.mod h1:qqTTPUK/HZPFgFQ/TJ3BzvTpF/dPtFVJXdQbCmeMxwc=
|
github.com/mholt/archiver/v3 v3.5.0/go.mod h1:qqTTPUK/HZPFgFQ/TJ3BzvTpF/dPtFVJXdQbCmeMxwc=
|
||||||
github.com/microcosm-cc/bluemonday v1.0.15 h1:J4uN+qPng9rvkBZBoBb8YGR+ijuklIMpSOZZLjYpbeY=
|
github.com/microcosm-cc/bluemonday v1.0.16 h1:kHmAq2t7WPWLjiGvzKa5o3HzSfahUKiOq7fAPUiMNIc=
|
||||||
github.com/microcosm-cc/bluemonday v1.0.15/go.mod h1:ZLvAzeakRwrGnzQEvstVzVt3ZpqOF2+sdFr0Om+ce30=
|
github.com/microcosm-cc/bluemonday v1.0.16/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM=
|
||||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||||
github.com/miekg/dns v1.1.42/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=
|
github.com/miekg/dns v1.1.42/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=
|
||||||
github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg=
|
github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg=
|
||||||
|
@ -1364,8 +1364,9 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
|
||||||
golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
|
golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
|
||||||
golang.org/x/net v0.0.0-20210331060903-cb1fcc7394e5/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
golang.org/x/net v0.0.0-20210331060903-cb1fcc7394e5/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||||
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
|
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
|
golang.org/x/net v0.0.0-20211020060615-d418f374d309 h1:A0lJIi+hcTR6aajJH4YqKWwohY4aW9RO7oRMcdv+HKI=
|
||||||
|
golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
|
|
4
vendor/github.com/microcosm-cc/bluemonday/.editorconfig
generated
vendored
Normal file
4
vendor/github.com/microcosm-cc/bluemonday/.editorconfig
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
1
vendor/github.com/microcosm-cc/bluemonday/.gitattributes
generated
vendored
Normal file
1
vendor/github.com/microcosm-cc/bluemonday/.gitattributes
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
* text=auto eol=lf
|
3
vendor/github.com/microcosm-cc/bluemonday/CREDITS.md
generated
vendored
3
vendor/github.com/microcosm-cc/bluemonday/CREDITS.md
generated
vendored
|
@ -4,4 +4,5 @@
|
||||||
1. Andrew Krasichkov @buglloc https://github.com/buglloc
|
1. Andrew Krasichkov @buglloc https://github.com/buglloc
|
||||||
1. Mike Samuel mikesamuel@gmail.com
|
1. Mike Samuel mikesamuel@gmail.com
|
||||||
1. Dmitri Shuralyov shurcooL@gmail.com
|
1. Dmitri Shuralyov shurcooL@gmail.com
|
||||||
1. https://github.com/opennota
|
1. opennota https://github.com/opennota https://gitlab.com/opennota
|
||||||
|
1. Tom Anthony https://www.tomanthony.co.uk/
|
8
vendor/github.com/microcosm-cc/bluemonday/Makefile
generated
vendored
8
vendor/github.com/microcosm-cc/bluemonday/Makefile
generated
vendored
|
@ -3,6 +3,7 @@
|
||||||
# all: Builds the code locally after testing
|
# all: Builds the code locally after testing
|
||||||
#
|
#
|
||||||
# fmt: Formats the source files
|
# fmt: Formats the source files
|
||||||
|
# fmt-check: Check if the source files are formated
|
||||||
# build: Builds the code locally
|
# build: Builds the code locally
|
||||||
# vet: Vets the code
|
# vet: Vets the code
|
||||||
# lint: Runs lint over the code (you do not need to fix everything)
|
# lint: Runs lint over the code (you do not need to fix everything)
|
||||||
|
@ -11,6 +12,8 @@
|
||||||
#
|
#
|
||||||
# install: Builds, tests and installs the code locally
|
# install: Builds, tests and installs the code locally
|
||||||
|
|
||||||
|
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")
|
||||||
|
|
||||||
.PHONY: all fmt build vet lint test cover install
|
.PHONY: all fmt build vet lint test cover install
|
||||||
|
|
||||||
# The first target is always the default action if `make` is called without
|
# The first target is always the default action if `make` is called without
|
||||||
|
@ -19,7 +22,10 @@
|
||||||
all: fmt vet test install
|
all: fmt vet test install
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
@gofmt -s -w ./$*
|
@gofmt -s -w ${GOFILES_NOVENDOR}
|
||||||
|
|
||||||
|
fmt-check:
|
||||||
|
@([ -z "$(shell gofmt -d $(GOFILES_NOVENDOR) | head)" ]) || (echo "Source is unformatted"; exit 1)
|
||||||
|
|
||||||
build:
|
build:
|
||||||
@go build
|
@go build
|
||||||
|
|
6
vendor/github.com/microcosm-cc/bluemonday/README.md
generated
vendored
6
vendor/github.com/microcosm-cc/bluemonday/README.md
generated
vendored
|
@ -180,7 +180,7 @@ p.AllowElementsMatching(regex.MustCompile(`^my-element-`))
|
||||||
|
|
||||||
Or add elements as a virtue of adding an attribute:
|
Or add elements as a virtue of adding an attribute:
|
||||||
```go
|
```go
|
||||||
// Not the recommended pattern, see the recommendation on using .Matching() below
|
// Note the recommended pattern, see the recommendation on using .Matching() below
|
||||||
p.AllowAttrs("nowrap").OnElements("td", "th")
|
p.AllowAttrs("nowrap").OnElements("td", "th")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ p.AllowElements("fieldset", "select", "option")
|
||||||
|
|
||||||
Although it's possible to handle inline CSS using `AllowAttrs` with a `Matching` rule, writing a single monolithic regular expression to safely process all inline CSS which you wish to allow is not a trivial task. Instead of attempting to do so, you can allow the `style` attribute on whichever element(s) you desire and use style policies to control and sanitize inline styles.
|
Although it's possible to handle inline CSS using `AllowAttrs` with a `Matching` rule, writing a single monolithic regular expression to safely process all inline CSS which you wish to allow is not a trivial task. Instead of attempting to do so, you can allow the `style` attribute on whichever element(s) you desire and use style policies to control and sanitize inline styles.
|
||||||
|
|
||||||
It is suggested that you use `Matching` (with a suitable regular expression)
|
It is strongly recommended that you use `Matching` (with a suitable regular expression)
|
||||||
`MatchingEnum`, or `MatchingHandler` to ensure each style matches your needs,
|
`MatchingEnum`, or `MatchingHandler` to ensure each style matches your needs,
|
||||||
but default handlers are supplied for most widely used styles.
|
but default handlers are supplied for most widely used styles.
|
||||||
|
|
||||||
|
@ -379,6 +379,8 @@ Both examples exhibit the same issue, they declare attributes but do not then sp
|
||||||
|
|
||||||
We are not yet including any tools to help allow and sanitize CSS. Which means that unless you wish to do the heavy lifting in a single regular expression (inadvisable), **you should not allow the "style" attribute anywhere**.
|
We are not yet including any tools to help allow and sanitize CSS. Which means that unless you wish to do the heavy lifting in a single regular expression (inadvisable), **you should not allow the "style" attribute anywhere**.
|
||||||
|
|
||||||
|
In the same theme, both `<script>` and `<style>` are considered harmful. These elements (and their content) will not be rendered by default, and require you to explicitly set `p.AllowUnsafe(true)`. You should be aware that allowing these elements defeats the purpose of using a HTML sanitizer as you would be explicitly allowing either JavaScript (and any plainly written XSS) and CSS (which can modify a DOM to insert JS), and additionally but limitations in this library mean it is not aware of whether HTML is validly structured and that can allow these elements to bypass some of the safety mechanisms built into the [WhatWG HTML parser standard](https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inselect).
|
||||||
|
|
||||||
It is not the job of bluemonday to fix your bad HTML, it is merely the job of bluemonday to prevent malicious HTML getting through. If you have mismatched HTML elements, or non-conforming nesting of elements, those will remain. But if you have well-structured HTML bluemonday will not break it.
|
It is not the job of bluemonday to fix your bad HTML, it is merely the job of bluemonday to prevent malicious HTML getting through. If you have mismatched HTML elements, or non-conforming nesting of elements, those will remain. But if you have well-structured HTML bluemonday will not break it.
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
1
vendor/github.com/microcosm-cc/bluemonday/go.mod
generated
vendored
1
vendor/github.com/microcosm-cc/bluemonday/go.mod
generated
vendored
|
@ -3,7 +3,6 @@ module github.com/microcosm-cc/bluemonday
|
||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
|
|
||||||
github.com/aymerick/douceur v0.2.0
|
github.com/aymerick/douceur v0.2.0
|
||||||
github.com/gorilla/css v1.0.0 // indirect
|
github.com/gorilla/css v1.0.0 // indirect
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
|
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
|
||||||
|
|
7
vendor/github.com/microcosm-cc/bluemonday/go.sum
generated
vendored
7
vendor/github.com/microcosm-cc/bluemonday/go.sum
generated
vendored
|
@ -1,17 +1,10 @@
|
||||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ=
|
|
||||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
|
|
||||||
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
|
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
|
||||||
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
||||||
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
|
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
|
||||||
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
|
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
|
||||||
golang.org/x/net v0.0.0-20210421230115-4e50805a0758 h1:aEpZnXcAmXkd6AvLb2OPt+EN1Zu/8Ne3pCqPjja5PXY=
|
|
||||||
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
|
|
||||||
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b h1:k+E048sYJHyVnsr1GDrRZWQ32D2C7lWs9JRc0bel53A=
|
|
||||||
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
|
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
|
30
vendor/github.com/microcosm-cc/bluemonday/policy.go
generated
vendored
30
vendor/github.com/microcosm-cc/bluemonday/policy.go
generated
vendored
|
@ -134,6 +134,19 @@ type Policy struct {
|
||||||
setOfElementsMatchingAllowedWithoutAttrs []*regexp.Regexp
|
setOfElementsMatchingAllowedWithoutAttrs []*regexp.Regexp
|
||||||
|
|
||||||
setOfElementsToSkipContent map[string]struct{}
|
setOfElementsToSkipContent map[string]struct{}
|
||||||
|
|
||||||
|
// Permits fundamentally unsafe elements.
|
||||||
|
//
|
||||||
|
// If false (default) then elements such as `style` and `script` will not be
|
||||||
|
// permitted even if declared in a policy. These elements when combined with
|
||||||
|
// untrusted input cannot be safely handled by bluemonday at this point in
|
||||||
|
// time.
|
||||||
|
//
|
||||||
|
// If true then `style` and `script` would be permitted by bluemonday if a
|
||||||
|
// policy declares them. However this is not recommended under any circumstance
|
||||||
|
// and can lead to XSS being rendered thus defeating the purpose of using a
|
||||||
|
// HTML sanitizer.
|
||||||
|
allowUnsafe bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type attrPolicy struct {
|
type attrPolicy struct {
|
||||||
|
@ -714,6 +727,23 @@ func (p *Policy) AllowElementsContent(names ...string) *Policy {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllowUnsafe permits fundamentally unsafe elements.
|
||||||
|
//
|
||||||
|
// If false (default) then elements such as `style` and `script` will not be
|
||||||
|
// permitted even if declared in a policy. These elements when combined with
|
||||||
|
// untrusted input cannot be safely handled by bluemonday at this point in
|
||||||
|
// time.
|
||||||
|
//
|
||||||
|
// If true then `style` and `script` would be permitted by bluemonday if a
|
||||||
|
// policy declares them. However this is not recommended under any circumstance
|
||||||
|
// and can lead to XSS being rendered thus defeating the purpose of using a
|
||||||
|
// HTML sanitizer.
|
||||||
|
func (p *Policy) AllowUnsafe(allowUnsafe bool) *Policy {
|
||||||
|
p.init()
|
||||||
|
p.allowUnsafe = allowUnsafe
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
// addDefaultElementsWithoutAttrs adds the HTML elements that we know are valid
|
// addDefaultElementsWithoutAttrs adds the HTML elements that we know are valid
|
||||||
// without any attributes to an internal map.
|
// without any attributes to an internal map.
|
||||||
// i.e. we know that <table> is valid, but <bdo> isn't valid as the "dir" attr
|
// i.e. we know that <table> is valid, but <bdo> isn't valid as the "dir" attr
|
||||||
|
|
41
vendor/github.com/microcosm-cc/bluemonday/sanitize.go
generated
vendored
41
vendor/github.com/microcosm-cc/bluemonday/sanitize.go
generated
vendored
|
@ -293,6 +293,17 @@ func (p *Policy) sanitize(r io.Reader, w io.Writer) error {
|
||||||
|
|
||||||
mostRecentlyStartedToken = normaliseElementName(token.Data)
|
mostRecentlyStartedToken = normaliseElementName(token.Data)
|
||||||
|
|
||||||
|
switch normaliseElementName(token.Data) {
|
||||||
|
case `script`:
|
||||||
|
if !p.allowUnsafe {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
case `style`:
|
||||||
|
if !p.allowUnsafe {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
aps, ok := p.elsAndAttrs[token.Data]
|
aps, ok := p.elsAndAttrs[token.Data]
|
||||||
if !ok {
|
if !ok {
|
||||||
aa, matched := p.matchRegex(token.Data)
|
aa, matched := p.matchRegex(token.Data)
|
||||||
|
@ -341,6 +352,17 @@ func (p *Policy) sanitize(r io.Reader, w io.Writer) error {
|
||||||
mostRecentlyStartedToken = ""
|
mostRecentlyStartedToken = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch normaliseElementName(token.Data) {
|
||||||
|
case `script`:
|
||||||
|
if !p.allowUnsafe {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
case `style`:
|
||||||
|
if !p.allowUnsafe {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if skipClosingTag && closingTagToSkipStack[len(closingTagToSkipStack)-1] == token.Data {
|
if skipClosingTag && closingTagToSkipStack[len(closingTagToSkipStack)-1] == token.Data {
|
||||||
closingTagToSkipStack = closingTagToSkipStack[:len(closingTagToSkipStack)-1]
|
closingTagToSkipStack = closingTagToSkipStack[:len(closingTagToSkipStack)-1]
|
||||||
if len(closingTagToSkipStack) == 0 {
|
if len(closingTagToSkipStack) == 0 {
|
||||||
|
@ -386,6 +408,17 @@ func (p *Policy) sanitize(r io.Reader, w io.Writer) error {
|
||||||
|
|
||||||
case html.SelfClosingTagToken:
|
case html.SelfClosingTagToken:
|
||||||
|
|
||||||
|
switch normaliseElementName(token.Data) {
|
||||||
|
case `script`:
|
||||||
|
if !p.allowUnsafe {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
case `style`:
|
||||||
|
if !p.allowUnsafe {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
aps, ok := p.elsAndAttrs[token.Data]
|
aps, ok := p.elsAndAttrs[token.Data]
|
||||||
if !ok {
|
if !ok {
|
||||||
aa, matched := p.matchRegex(token.Data)
|
aa, matched := p.matchRegex(token.Data)
|
||||||
|
@ -425,15 +458,23 @@ func (p *Policy) sanitize(r io.Reader, w io.Writer) error {
|
||||||
case `script`:
|
case `script`:
|
||||||
// not encouraged, but if a policy allows JavaScript we
|
// not encouraged, but if a policy allows JavaScript we
|
||||||
// should not HTML escape it as that would break the output
|
// should not HTML escape it as that would break the output
|
||||||
|
//
|
||||||
|
// requires p.AllowUnsafe()
|
||||||
|
if p.allowUnsafe {
|
||||||
if _, err := buff.WriteString(token.Data); err != nil {
|
if _, err := buff.WriteString(token.Data); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case "style":
|
case "style":
|
||||||
// not encouraged, but if a policy allows CSS styles we
|
// not encouraged, but if a policy allows CSS styles we
|
||||||
// should not HTML escape it as that would break the output
|
// should not HTML escape it as that would break the output
|
||||||
|
//
|
||||||
|
// requires p.AllowUnsafe()
|
||||||
|
if p.allowUnsafe {
|
||||||
if _, err := buff.WriteString(token.Data); err != nil {
|
if _, err := buff.WriteString(token.Data); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
// HTML escape the text
|
// HTML escape the text
|
||||||
if _, err := buff.WriteString(token.String()); err != nil {
|
if _, err := buff.WriteString(token.String()); err != nil {
|
||||||
|
|
1
vendor/github.com/microcosm-cc/bluemonday/stringwriterwriter_go1.12.go
generated
vendored
1
vendor/github.com/microcosm-cc/bluemonday/stringwriterwriter_go1.12.go
generated
vendored
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build go1.12
|
||||||
// +build go1.12
|
// +build go1.12
|
||||||
|
|
||||||
package bluemonday
|
package bluemonday
|
||||||
|
|
1
vendor/github.com/microcosm-cc/bluemonday/stringwriterwriter_ltgo1.12.go
generated
vendored
1
vendor/github.com/microcosm-cc/bluemonday/stringwriterwriter_ltgo1.12.go
generated
vendored
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build go1.1 && !go1.12
|
||||||
// +build go1.1,!go1.12
|
// +build go1.1,!go1.12
|
||||||
|
|
||||||
package bluemonday
|
package bluemonday
|
||||||
|
|
26
vendor/golang.org/x/net/internal/socket/complete_dontwait.go
generated
vendored
Normal file
26
vendor/golang.org/x/net/internal/socket/complete_dontwait.go
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
// Copyright 2021 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
||||||
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
||||||
|
|
||||||
|
package socket
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ioComplete checks the flags and result of a syscall, to be used as return
|
||||||
|
// value in a syscall.RawConn.Read or Write callback.
|
||||||
|
func ioComplete(flags int, operr error) bool {
|
||||||
|
if flags&syscall.MSG_DONTWAIT != 0 {
|
||||||
|
// Caller explicitly said don't wait, so always return immediately.
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if operr == syscall.EAGAIN || operr == syscall.EWOULDBLOCK {
|
||||||
|
// No data available, block for I/O and try again.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
22
vendor/golang.org/x/net/internal/socket/complete_nodontwait.go
generated
vendored
Normal file
22
vendor/golang.org/x/net/internal/socket/complete_nodontwait.go
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright 2021 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build aix || windows || zos
|
||||||
|
// +build aix windows zos
|
||||||
|
|
||||||
|
package socket
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ioComplete checks the flags and result of a syscall, to be used as return
|
||||||
|
// value in a syscall.RawConn.Read or Write callback.
|
||||||
|
func ioComplete(flags int, operr error) bool {
|
||||||
|
if operr == syscall.EAGAIN || operr == syscall.EWOULDBLOCK {
|
||||||
|
// No data available, block for I/O and try again.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
11
vendor/golang.org/x/net/internal/socket/rawconn_mmsg.go
generated
vendored
11
vendor/golang.org/x/net/internal/socket/rawconn_mmsg.go
generated
vendored
|
@ -10,7 +10,6 @@ package socket
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Conn) recvMsgs(ms []Message, flags int) (int, error) {
|
func (c *Conn) recvMsgs(ms []Message, flags int) (int, error) {
|
||||||
|
@ -28,10 +27,7 @@ func (c *Conn) recvMsgs(ms []Message, flags int) (int, error) {
|
||||||
var n int
|
var n int
|
||||||
fn := func(s uintptr) bool {
|
fn := func(s uintptr) bool {
|
||||||
n, operr = recvmmsg(s, hs, flags)
|
n, operr = recvmmsg(s, hs, flags)
|
||||||
if operr == syscall.EAGAIN {
|
return ioComplete(flags, operr)
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
if err := c.c.Read(fn); err != nil {
|
if err := c.c.Read(fn); err != nil {
|
||||||
return n, err
|
return n, err
|
||||||
|
@ -60,10 +56,7 @@ func (c *Conn) sendMsgs(ms []Message, flags int) (int, error) {
|
||||||
var n int
|
var n int
|
||||||
fn := func(s uintptr) bool {
|
fn := func(s uintptr) bool {
|
||||||
n, operr = sendmmsg(s, hs, flags)
|
n, operr = sendmmsg(s, hs, flags)
|
||||||
if operr == syscall.EAGAIN {
|
return ioComplete(flags, operr)
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
if err := c.c.Write(fn); err != nil {
|
if err := c.c.Write(fn); err != nil {
|
||||||
return n, err
|
return n, err
|
||||||
|
|
11
vendor/golang.org/x/net/internal/socket/rawconn_msg.go
generated
vendored
11
vendor/golang.org/x/net/internal/socket/rawconn_msg.go
generated
vendored
|
@ -9,7 +9,6 @@ package socket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Conn) recvMsg(m *Message, flags int) error {
|
func (c *Conn) recvMsg(m *Message, flags int) error {
|
||||||
|
@ -25,10 +24,7 @@ func (c *Conn) recvMsg(m *Message, flags int) error {
|
||||||
var n int
|
var n int
|
||||||
fn := func(s uintptr) bool {
|
fn := func(s uintptr) bool {
|
||||||
n, operr = recvmsg(s, &h, flags)
|
n, operr = recvmsg(s, &h, flags)
|
||||||
if operr == syscall.EAGAIN || operr == syscall.EWOULDBLOCK {
|
return ioComplete(flags, operr)
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
if err := c.c.Read(fn); err != nil {
|
if err := c.c.Read(fn); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -64,10 +60,7 @@ func (c *Conn) sendMsg(m *Message, flags int) error {
|
||||||
var n int
|
var n int
|
||||||
fn := func(s uintptr) bool {
|
fn := func(s uintptr) bool {
|
||||||
n, operr = sendmsg(s, &h, flags)
|
n, operr = sendmsg(s, &h, flags)
|
||||||
if operr == syscall.EAGAIN || operr == syscall.EWOULDBLOCK {
|
return ioComplete(flags, operr)
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
if err := c.c.Write(fn); err != nil {
|
if err := c.c.Write(fn); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
4
vendor/modules.txt
vendored
4
vendor/modules.txt
vendored
|
@ -614,7 +614,7 @@ github.com/mholt/acmez/acme
|
||||||
# github.com/mholt/archiver/v3 v3.5.0
|
# github.com/mholt/archiver/v3 v3.5.0
|
||||||
## explicit
|
## explicit
|
||||||
github.com/mholt/archiver/v3
|
github.com/mholt/archiver/v3
|
||||||
# github.com/microcosm-cc/bluemonday v1.0.15
|
# github.com/microcosm-cc/bluemonday v1.0.16
|
||||||
## explicit
|
## explicit
|
||||||
github.com/microcosm-cc/bluemonday
|
github.com/microcosm-cc/bluemonday
|
||||||
github.com/microcosm-cc/bluemonday/css
|
github.com/microcosm-cc/bluemonday/css
|
||||||
|
@ -886,7 +886,7 @@ golang.org/x/crypto/ssh/knownhosts
|
||||||
# golang.org/x/mod v0.4.2
|
# golang.org/x/mod v0.4.2
|
||||||
golang.org/x/mod/module
|
golang.org/x/mod/module
|
||||||
golang.org/x/mod/semver
|
golang.org/x/mod/semver
|
||||||
# golang.org/x/net v0.0.0-20210614182718-04defd469f4e
|
# golang.org/x/net v0.0.0-20211020060615-d418f374d309
|
||||||
## explicit
|
## explicit
|
||||||
golang.org/x/net/bpf
|
golang.org/x/net/bpf
|
||||||
golang.org/x/net/context
|
golang.org/x/net/context
|
||||||
|
|
Reference in a new issue