@@ -74,6 +74,9 @@ type Policy struct {
74
74
// When true, add crossorigin="anonymous" to HTML audio, img, link, script, and video tags
75
75
requireCrossOriginAnonymous bool
76
76
77
+ // When true, add and filter sandbox attribute on iframe tags
78
+ requireSandboxOnIFrame map [string ]bool
79
+
77
80
// When true add target="_blank" to fully qualified links
78
81
// Will add for href="http://foo"
79
82
// Will skip for href="/foo" or href="foo"
@@ -189,6 +192,25 @@ type stylePolicyBuilder struct {
189
192
190
193
type urlPolicy func (url * url.URL ) (allowUrl bool )
191
194
195
+ type SandboxValue int64
196
+
197
+ const (
198
+ SandboxAllowDownloads SandboxValue = iota
199
+ SandboxAllowDownloadsWithoutUserActivation
200
+ SandboxAllowForms
201
+ SandboxAllowModals
202
+ SandboxAllowOrientationLock
203
+ SandboxAllowPointerLock
204
+ SandboxAllowPopups
205
+ SandboxAllowPopupsToEscapeSandbox
206
+ SandboxAllowPresentation
207
+ SandboxAllowSameOrigin
208
+ SandboxAllowScripts
209
+ SandboxAllowStorageAccessByUserActivation
210
+ SandboxAllowTopNavigation
211
+ SandboxAllowTopNavigationByUserActivation
212
+ )
213
+
192
214
// init initializes the maps if this has not been done already
193
215
func (p * Policy ) init () {
194
216
if ! p .initialized {
@@ -680,6 +702,56 @@ func (p *Policy) AllowURLSchemeWithCustomPolicy(
680
702
return p
681
703
}
682
704
705
+ func (p * Policy ) RequireSandboxOnIFrame (vals ... SandboxValue ) {
706
+ p .requireSandboxOnIFrame = make (map [string ]bool )
707
+
708
+ for val := range vals {
709
+ switch SandboxValue (val ) {
710
+ case SandboxAllowDownloads :
711
+ p .requireSandboxOnIFrame ["allow-downloads" ] = true
712
+
713
+ case SandboxAllowDownloadsWithoutUserActivation :
714
+ p .requireSandboxOnIFrame ["allow-downloads-without-user-activation" ] = true
715
+
716
+ case SandboxAllowForms :
717
+ p .requireSandboxOnIFrame ["allow-forms" ] = true
718
+
719
+ case SandboxAllowModals :
720
+ p .requireSandboxOnIFrame ["allow-modals" ] = true
721
+
722
+ case SandboxAllowOrientationLock :
723
+ p .requireSandboxOnIFrame ["allow-orientation-lock" ] = true
724
+
725
+ case SandboxAllowPointerLock :
726
+ p .requireSandboxOnIFrame ["allow-pointer-lock" ] = true
727
+
728
+ case SandboxAllowPopups :
729
+ p .requireSandboxOnIFrame ["allow-popups" ] = true
730
+
731
+ case SandboxAllowPopupsToEscapeSandbox :
732
+ p .requireSandboxOnIFrame ["allow-popups-to-escape-sandbox" ] = true
733
+
734
+ case SandboxAllowPresentation :
735
+ p .requireSandboxOnIFrame ["allow-presentation" ] = true
736
+
737
+ case SandboxAllowSameOrigin :
738
+ p .requireSandboxOnIFrame ["allow-same-origin" ] = true
739
+
740
+ case SandboxAllowScripts :
741
+ p .requireSandboxOnIFrame ["allow-scripts" ] = true
742
+
743
+ case SandboxAllowStorageAccessByUserActivation :
744
+ p .requireSandboxOnIFrame ["allow-storage-access-by-user-activation" ] = true
745
+
746
+ case SandboxAllowTopNavigation :
747
+ p .requireSandboxOnIFrame ["allow-top-navigation" ] = true
748
+
749
+ case SandboxAllowTopNavigationByUserActivation :
750
+ p .requireSandboxOnIFrame ["allow-top-navigation-by-user-activation" ] = true
751
+ }
752
+ }
753
+ }
754
+
683
755
// AddSpaceWhenStrippingTag states whether to add a single space " " when
684
756
// removing tags that are not allowed by the policy.
685
757
//
0 commit comments