Skip to content

CSP: make available a reliable method for obtaining a reference to the global object #2

Closed
@mikewest

Description

@mikewest

From @michaelficarra on October 6, 2015 23:38

At times, it is necessary to obtain a reference to the global object. In different environments, this object has non-standard, writable self-references: global in node, window in certain browser contexts, self in other browser contexts, etc. It is not a good practice to rely upon these references. For this reason, a particular pattern using the Function constructor is the only reliable method (of which I'm aware) for obtaining a reference to the global object in any context (strict/sloppy mode, module/script).

var honestToGodGlobalObject = Function("return this")();

Because this is a use of the Function constructor, CSP does not allow this pattern without adding 'unsafe-eval' to my policy. How can we make an exception to allow this pattern or something equivalent?

Copied from original issue: w3c/webappsec#501

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions