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

append frame-src config in test mode #152

Merged
merged 2 commits into from
Jan 8, 2021

Conversation

chbonser
Copy link
Contributor

@chbonser chbonser commented Sep 8, 2020

Addresses #151

Note this works in my case because my app has frame-src defined. From the failing tests it appears appendSourceList does not handle the case of a missing frame-src properly. Should appendSourceList get smarter or should this problem get solved via another approach?

@jelhan
Copy link
Collaborator

jelhan commented Sep 8, 2020

Thanks so a lot for working on this! Looks good to me. Haven't had the time to look at the failing test yet.

From the failing tests it appears appendSourceList does not handle the case of a missing frame-src properly. Should appendSourceList get smarter or should this problem get solved via another approach?

It should already be that smart:

if (!Array.isArray(value)) {
// initialize source list with an copy of default-src (see above)
policyObject[directiveName] = policyObject['default-src'] ? policyObject['default-src'].slice() : [];
}

@rwjblue
Copy link
Owner

rwjblue commented Oct 19, 2020

@chbonser - Have you had any time to debug the failure here?

@jelhan
Copy link
Collaborator

jelhan commented Oct 19, 2020

@rwjblue I fear it's related to the buggy ember-cli-addon-tests setup. I working on the side on a replacement for that one but haven't had the time to finish it yet.

@jelhan jelhan added the bug label Nov 4, 2020
@jelhan jelhan added this to the Release v2.0 milestone Nov 4, 2020
@jelhan jelhan mentioned this pull request Nov 4, 2020
10 tasks
@jelhan jelhan closed this Nov 9, 2020
@jelhan jelhan reopened this Nov 9, 2020
@jelhan
Copy link
Collaborator

jelhan commented Nov 9, 2020

Closed and reopened to trigger another Travis run after test suite was refactored in #154.

@jelhan
Copy link
Collaborator

jelhan commented Nov 9, 2020

Getting a way more helpful error in CI now:

  1) e2e: provides test support
       includes frame-src required by testem
         includes frame-src required by testem in CSP delivered by meta tag:
     AssertionError: expected 'default-src \'none\'; script-src \'self\' \'nonce-abcdefg\' localhost:49741 0.0.0.0:49741; font-src \'self\'; connect-src \'self\' ws://localhost:49741 ws://0.0.0.0:49741; img-src \'self\'; style-src \'self\'; media-src \'self\'; frame-src \'none\' \'self\';' to include 'frame-src \'self\';'
      at Context.<anonymous> (node-tests/e2e/test-support-test.js:232:38)

  2) e2e: provides test support
       includes frame-src required by testem
         includes frame-src required by testem in CSP delivered by HTTP header:
     AssertionError: expected 'default-src \'none\'; script-src \'self\' \'nonce-abcdefg\' localhost:49741 0.0.0.0:49741; font-src \'self\'; connect-src \'self\' ws://localhost:49741 ws://0.0.0.0:49741; img-src \'self\'; style-src \'self\'; media-src \'self\'; frame-src \'none\' \'self\';' to include 'frame-src \'self\';'
      at Context.<anonymous> (node-tests/e2e/test-support-test.js:244:30)
      at process._tickCallback (internal/process/next_tick.js:68:7)

The test tries to find the string frame-src 'self';. But the CSP includes frame-src 'none' 'self';'.

This highlights a bug in appendSourceList utility. It does not remove an existing 'none' keyword if applying an expression.

@jelhan
Copy link
Collaborator

jelhan commented Nov 9, 2020

Closing and reopening again after #156 has been merged. It should address the bug described in my last comment. Let's see.

@jelhan jelhan reopened this Nov 9, 2020
@jelhan
Copy link
Collaborator

jelhan commented Nov 10, 2020

It's working. 👏

To avoid a regression I would prefer to have test coverage. There are already some tests coverage for frame-src in tests:

describe('includes frame-src required by testem', function() {
before(async function() {
await setConfig(testProject, {
delivery: ['header', 'meta'],
reportOnly: false,
});
await testProject.startEmberServer({
port: '49741',
});
});
after(async function() {
await testProject.stopEmberServer();
await removeConfig(testProject);
});
it('includes frame-src required by testem in CSP delivered by meta tag', async function() {
let testsIndexHtml = await testProject.readFile('dist/tests/index.html', 'utf8');
let [,cspInTestsIndexHtml] = testsIndexHtml.match(CSP_META_TAG_REG_EXP);
expect(cspInTestsIndexHtml).to.include("frame-src 'self';");
});
it('includes frame-src required by testem in CSP delivered by HTTP header', async function() {
let responseForTests = await request({
url: 'http://localhost:49741/tests',
headers: {
'Accept': 'text/html'
}
});
let cspForTests = responseForTests.headers['content-security-policy'];
expect(cspForTests).to.include("frame-src 'self';");
});
});
An additional test should be added that it does not remove existing frame-src directive but appends to it.

@chbonser: Do you have time to add such a test or should I take over? Totally understand if you don't have time or motivation to do so after two months.

@chbonser
Copy link
Contributor Author

@jelhan I am buried in other things at the moment but I'll try to squeeze in time later this week to add the test you mentioned.

@jelhan
Copy link
Collaborator

jelhan commented Jan 8, 2021

Rebased and added a failing tests. Thanks a lot @chbonser for debugging and providing the original fix! I'm sorry that it took that long to get it in.

@jelhan jelhan merged commit d0be648 into rwjblue:master Jan 8, 2021
@chbonser
Copy link
Contributor Author

Thanks @jelhan. Sorry I wasn't able to add the extra test coverage!

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

Successfully merging this pull request may close these issues.

3 participants