Skip to content

Commit 0c3dc35

Browse files
authored
Merge pull request #5 from JuliaComputing/sp/no-svg-math
fix: remove `math` and `svg` content by default
2 parents e4f6a80 + 55d768d commit 0c3dc35

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

.github/workflows/CI.yml

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,20 @@ on:
44
push:
55
branches:
66
- master
7-
tags: '*'
7+
tags: ["*"]
88
jobs:
99
test:
10-
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
1110
runs-on: ${{ matrix.os }}
1211
strategy:
13-
fail-fast: false
1412
matrix:
15-
version:
16-
- '1.6'
17-
- '1.7'
18-
- 'nightly'
19-
os:
20-
- ubuntu-latest
21-
arch:
22-
- x64
23-
env:
24-
PYTHON: ""
13+
channel: ['1.6', '1.10', '1.12', 'nightly']
14+
os: [ubuntu-latest]
2515
steps:
26-
- uses: actions/checkout@v2
27-
- uses: julia-actions/setup-julia@v1
16+
- uses: actions/checkout@v4
17+
- uses: julia-actions/install-juliaup@v2
2818
with:
29-
version: ${{ matrix.version }}
30-
arch: ${{ matrix.arch }}
31-
- uses: actions/cache@v1
19+
channel: ${{matrix.channel}}
20+
- uses: actions/cache@v4
3221
env:
3322
cache-name: cache-artifacts
3423
with:
@@ -39,4 +28,4 @@ jobs:
3928
${{ runner.os }}-test-
4029
${{ runner.os }}-
4130
- uses: julia-actions/julia-buildpkg@v1
42-
- uses: julia-actions/julia-runtest@v1
31+
- uses: julia-actions/julia-runtest@v1

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Whitelist-based HTML sanitizer inspired by [sanitize](https://github.com/rgrove/
66

77
HTMLSanitizer.jl parses your source HTML with [Gumbo.jl](https://github.com/JuliaWeb/Gumbo.jl) and then filters tags and attributes according to a whitelist. The default whitelists are fairly close to GitHubs pipeline for rendering markdown to HTML.
88

9+
> [!WARNING]
10+
>
11+
> HTMLSanitizer removes the content of `<math>` and `<svg>` [foreign elements](https://html.spec.whatwg.org/multipage/syntax.html#foreign-elements) by default. Allowing these elements may cause vulnerabilities.
12+
913
## Usage
1014

1115
```

src/HTMLSanitizer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ const WHITELIST = Dict(
147147
"summary","details","caption","figure","figcaption","abbr","bdo","cite","dfn","mark",
148148
"small","span","time","wbr","center"
149149
],
150-
:remove_contents => ["script"],
150+
:remove_contents => ["script", "math", "svg"],
151151
:attributes => Dict(
152152
"a" => ["href"],
153153
"img" => ["src", "longdesc"],

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ using Test
124124
</details>"""
125125
@test replace(orig, "\n" => "") == replace(HTMLSanitizer.sanitize(orig), "\n" => "")
126126
end
127+
128+
@testset "svg" begin
129+
orig = """<svg><style>&lt;/style>&lt;img src onerror=alert(1)>"""
130+
@test "" == HTMLSanitizer.sanitize(orig)
131+
end
132+
133+
@testset "math" begin
134+
orig = """<math><style>&lt;/style>&lt;img src onerror=alert(1)>"""
135+
@test "" == HTMLSanitizer.sanitize(orig)
136+
end
127137
end
128138

129139
@testset "preserve relevant whitespace" begin

0 commit comments

Comments
 (0)