Skip to content

Commit

Permalink
Merge pull request #138 from kiwiz/main
Browse files Browse the repository at this point in the history
Fix incorrect handling of iframe SandboxValues
  • Loading branch information
buro9 committed Feb 7, 2022
2 parents ce0adc5 + 1d1aa60 commit 078c4be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion policy.go
Expand Up @@ -707,7 +707,7 @@ func (p *Policy) AllowURLSchemeWithCustomPolicy(
func (p *Policy) RequireSandboxOnIFrame(vals ...SandboxValue) {
p.requireSandboxOnIFrame = make(map[string]bool)

for val := range vals {
for _, val := range vals {
switch SandboxValue(val) {
case SandboxAllowDownloads:
p.requireSandboxOnIFrame["allow-downloads"] = true
Expand Down
6 changes: 3 additions & 3 deletions sanitize_test.go
Expand Up @@ -1874,10 +1874,10 @@ func TestIssue107(t *testing.T) {
func TestIFrameSandbox(t *testing.T) {
p := NewPolicy()
p.AllowAttrs("sandbox").OnElements("iframe")
p.RequireSandboxOnIFrame(SandboxAllowDownloads)
p.RequireSandboxOnIFrame(SandboxAllowForms, SandboxAllowPopups)

in := `<iframe src="http://example.com" sandbox="allow-forms allow-downloads allow-downloads"></iframe>`
expected := `<iframe sandbox="allow-downloads"></iframe>`
in := `<iframe src="http://example.com" sandbox="allow-forms allow-downloads allow-downloads allow-popups"></iframe>`
expected := `<iframe sandbox="allow-forms allow-popups"></iframe>`
out := p.Sanitize(in)
if out != expected {
t.Errorf(
Expand Down

0 comments on commit 078c4be

Please sign in to comment.