Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect handling of iframe SandboxValues #138

Merged
merged 1 commit into from Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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