f / f/graphql.js

Update fragmentPath method to not use Function constructor (CSP 'unsafe-eval' issue)

Open
#48 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.3k
Forks
88
PR merge metrics
No merged PRs in 30d

Description

I'm testing out this module in a browser extension and get a CSP error because of the Function constructor used in the `fragmentPath` method [here](https://github.com/f/graphql.js/blob/master/graphql.js#L192) (trips the 'unsafe-eval' source expression for the 'script-src' directive; [more info](https://w3c.github.io/webappsec-csp/#directive-script-src)). This prevents me from using the module as-is with my extension's CSP.

In my testing, I was able to just replace that Function constructor:
```javascript
var getter = new Function("fragments", "return fragments." + path.replace(/\./g, FRAGMENT_SEPERATOR));
```

with this:
```javascript
var obj = fragments[path.replace(/\./g, FRAGMENT_SEPERATOR)];
```

Without issue.

Is this a change that would be considered for the module? Or am I missing something that requires the current usage?

Thanks!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.