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

Using new Function violates common security practice #91

Closed
nhusher opened this issue Mar 5, 2019 · 5 comments
Closed

Using new Function violates common security practice #91

nhusher opened this issue Mar 5, 2019 · 5 comments

Comments

@nhusher
Copy link

nhusher commented Mar 5, 2019

This library uses new Function, which is equivalent to the eval function. Under common sense security regimes, both new Function and eval are disallowed, including in the browser using CSP.

@mourner
Copy link
Owner

mourner commented Mar 5, 2019

If you're under CSP restrictions, don't use the format option. You can either use the default format, or override compareMinX, compareMinY and toBBox methods to support a custom format without eval.

@mourner mourner closed this as completed Mar 5, 2019
@photonstorm
Copy link

@nhusher if you're interested, we have our own version of rbush here that we slightly modified to get around the CSP limitation, while still retaining the speed of that function.

@mourner
Copy link
Owner

mourner commented Mar 5, 2019

@photonstorm any reason you decided to fork the library instead of just overriding the methods above? I think switching back to a direct dependency would be beneficial — you would get any potential bugfixes and performance improvements from upstream.

function customRBush(maxEntries) {
    var tree = rbush(maxEntries);
    tree.compareMinX = compareMinX;
    tree.compareMinY = compareMinY;
    tree.toBBox = toBBox;
    return tree;
}
function compareMinX(a, b) { return a.left - b.left; }
function compareMinY(a, b) { return a.top - b.top; }
function toBBox(a) {
    return {
        minX: a.left,
        minY: a.top,
        maxX: a.right,
        maxY: a.bottom
    };
}

@photonstorm
Copy link

@mourner The main reason is because we needed a different way of requiring QuickSelect. You only release new versions once a year (if that) and they're generally really small updates, so it's trivial to manage from our end. If you were in a rapid development cycle then we'd do it differently, but I'm quite glad it's nice and stable and rarely changing.

@mourner
Copy link
Owner

mourner commented May 14, 2019

Note that RBush v3.0 eliminates eval and is fully CSP-compliant. See #93

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants