Skip to content

Usage of DOMPurify requires "unsafe-eval" CSP since 1.0.0 #249

@frigus02

Description

@frigus02

As described in the CSP spec, using Function(...) with a string requires the "unsafe-eval" CSP rule.

This is now the case with the implementation of getGlobal:

function getGlobal() {
// eslint-disable-next-line no-new-func
return Function('return this')();
}

I'm not sure why this pattern is used here. I guess you want to be sure to get the global object.

Do you think you can release a CSP compliant version of DOMPurify, which just returns window?

Activity

cure53

cure53 commented on Aug 22, 2017

@cure53
Owner

Good point, can we work around that @tdeekens?

tdeekens

tdeekens commented on Aug 22, 2017

@tdeekens
Collaborator

As far as I remember it was needed to either get the node.global or the window. Suggestions welcome.

tdeekens

tdeekens commented on Aug 22, 2017

@tdeekens
Collaborator

Not sure if moving to https://github.com/purposeindustries/window-or-global/blob/master/lib/index.js would solve the issue while still be working.

cure53

cure53 commented on Aug 22, 2017

@cure53
Owner

It would for sure not cause CSP warnings :D

tdeekens

tdeekens commented on Aug 22, 2017

@tdeekens
Collaborator

The problem with the library is that this will be rewritten to undefined using rollup (https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined). I am not really sure what the "semantics" behind the idea for "root" at say

DOMPurify/src/purify.js

Lines 1 to 12 in a992d3a

;(function(factory) {
'use strict';
/* global window: false, define: false, module: false */
var root = typeof window === 'undefined' ? null : window;
if (typeof define === 'function' && define.amd) {
define(function(){ return factory(root); });
} else if (typeof module !== 'undefined') {
module.exports = factory(root);
} else {
root.DOMPurify = factory(root);
}
which is where the factory was used and interacted with which we can't do now as we bundle the library up.

tdeekens

tdeekens commented on Aug 22, 2017

@tdeekens
Collaborator

Check #250

tdeekens

tdeekens commented on Aug 22, 2017

@tdeekens
Collaborator

Build is green. I guess it's time for 1.0.2 after all.

frigus02

frigus02 commented on Aug 22, 2017

@frigus02
Author

Thanks again for the quick solution :-).

tdeekens

tdeekens commented on Aug 22, 2017

@tdeekens
Collaborator

You're welcome. I hope the solution covers all our use cases of consumers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @tdeekens@frigus02@cure53

        Issue actions