-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[DataGrid] Fix eval blocked by CSP #9863
Conversation
Should we add a test for this? Do we have a test setup that can handle adding a CSP header? |
Netlify deploy previewNetlify deploy preview: https://deploy-preview-9863--material-ui-x.netlify.app/ Updated pagesNo updates. These are the results for the performance tests:
|
Should we add a test for this? It should be fairly easy to add an e2e test that would inject CSP |
The current implementation only detects eval once at startup. Should we move the check at each filter call? I don't love it but it's probably not very expensive. |
Oh, right. Yes, moving the check to the filter call sounds good to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would using Function
over eval
be safer and yield similar performance?
@@ -278,25 +290,27 @@ describe('<DataGrid /> - Filter', () => { | |||
const ALL_ROWS = ['', '', '', 'France (fr)', 'Germany', '0', '1']; | |||
|
|||
it('should filter with operator "contains"', () => { | |||
expect(getRows({ operator: 'contains', value: 'Fra' })).to.deep.equal(['France (fr)']); | |||
testEval(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means we no longer run any of the assertions below in the tests, no? It seems it's not what we intended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT we're running them twice, eval and non-eval. testEval
is synchronous. Unless I'm misunderstanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understood, this would provide the intended behavior:
diff --git a/packages/grid/x-data-grid/src/tests/filtering.DataGrid.test.tsx b/packages/grid/x-data-grid/src/tests/filtering.DataGrid.test.tsx
index e5ab37fa5..2b42b9f7b 100644
--- a/packages/grid/x-data-grid/src/tests/filtering.DataGrid.test.tsx
+++ b/packages/grid/x-data-grid/src/tests/filtering.DataGrid.test.tsx
@@ -44,16 +44,14 @@ describe('<DataGrid /> - Filter', () => {
let disableEval = false;
function testEval(fn: Function) {
- return () => {
- disableEval = false;
- fn();
- disableEval = true;
- fn();
- disableEval = false;
- };
+ fn();
+ disableEval = true;
+ fn();
+ disableEval = false;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed this when adding new tests 😅
#10587
@@ -245,6 +245,12 @@ DataGridPremiumRaw.propTypes = { | |||
* @default false | |||
*/ | |||
disableDensitySelector: PropTypes.bool, | |||
/** | |||
* If `true`, `eval()` is not used for performance optimization. | |||
* @default false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure about this opt-out? eval could be a security hole.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have reviewed the eval'd code in #9635 and #9120 and we haven't found any remaining security risk. In particular, we ensure that no user inputted string can end up in the eval'd code without being properly escaped (aka no XSS). There are only two user inputs, applier.item.id
and applier.item.field
. We pass them both through JSON.stringify
, which by the spec returns a valid & properly escaped string representation for JS/JSON.
If we do find a security risk, then it would be best to simply not include the feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright 👍
Not safer, it's the same fundamental mechanism, |
Closes #9771
Feature-detect eval at runtime and only use it if available.