Class SandboxDirective

java.lang.Object
org.htmlunit.csp.Directive
org.htmlunit.csp.directive.SandboxDirective

public class SandboxDirective extends Directive
Represents the sandbox CSP directive.

The sandbox directive applies restrictions to the protected resource similar to the <iframe sandbox> attribute. When present with no keywords, the strictest sandbox is applied. Individual restrictions can be lifted by including the corresponding allow-* keyword.

Author:
Salvation Team
See Also:
  • Constructor Details

    • SandboxDirective

      public SandboxDirective(List<String> values, Directive.DirectiveErrorConsumer errors)
      Parses a sandbox directive from the given list of keyword values.

      Each token is matched case-insensitively against the known sandbox keywords. Duplicates and unrecognised keywords are reported through the supplied errors consumer.

      Parameters:
      values - the raw string values (sandbox keywords) for this directive
      errors - consumer that receives parsing errors and warnings
  • Method Details

    • allowDownloads

      public boolean allowDownloads()
      Returns whether the allow-downloads sandbox keyword is present.
      Returns:
      true if downloads are allowed
    • allowForms

      public boolean allowForms()
      Returns whether the allow-forms sandbox keyword is present.
      Returns:
      true if form submission is allowed
    • allowModals

      public boolean allowModals()
      Returns whether the allow-modals sandbox keyword is present.
      Returns:
      true if modal dialogs (e.g. alert()) are allowed
    • allowOrientationLock

      public boolean allowOrientationLock()
      Returns whether the allow-orientation-lock sandbox keyword is present.
      Returns:
      true if screen orientation locking is allowed
    • allowPointerLock

      public boolean allowPointerLock()
      Returns whether the allow-pointer-lock sandbox keyword is present.
      Returns:
      true if the Pointer Lock API is allowed
    • allowPopups

      public boolean allowPopups()
      Returns whether the allow-popups sandbox keyword is present.
      Returns:
      true if popups (e.g. window.open(), target="_blank") are allowed
    • allowPopupsToEscapeSandbox

      public boolean allowPopupsToEscapeSandbox()
      Returns whether the allow-popups-to-escape-sandbox sandbox keyword is present.
      Returns:
      true if popups are allowed to open without inheriting the sandbox
    • allowPresentation

      public boolean allowPresentation()
      Returns whether the allow-presentation sandbox keyword is present.
      Returns:
      true if the Presentation API is allowed
    • allowSameOrigin

      public boolean allowSameOrigin()
      Returns whether the allow-same-origin sandbox keyword is present.
      Returns:
      true if the content is treated as being from its normal origin
    • allowScripts

      public boolean allowScripts()
      Returns whether the allow-scripts sandbox keyword is present.
      Returns:
      true if script execution is allowed
    • allowStorageAccessByUserActivation

      public boolean allowStorageAccessByUserActivation()
      Returns whether the allow-storage-access-by-user-activation sandbox keyword is present.
      Returns:
      true if the Storage Access API is allowed with user activation
    • allowTopNavigation

      public boolean allowTopNavigation()
      Returns whether the allow-top-navigation sandbox keyword is present.
      Returns:
      true if navigation of the top-level browsing context is allowed
    • allowTopNavigationByUserActivation

      public boolean allowTopNavigationByUserActivation()
      Returns whether the allow-top-navigation-by-user-activation sandbox keyword is present.
      Returns:
      true if top-level navigation is allowed only with user activation