Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix(csp): fix csp auto-detection and stylesheet injection #4444

Closed
wants to merge 1 commit into from

Conversation

IgorMinar
Copy link
Contributor

When we refactored , we broke the csp mode because the previous implementation
relied on the fact that it was ok to lazy initialize the .csp property, this
is not the case any more.

Besides, we need to know about csp mode during bootstrap and avoid injecting the
stylesheet when csp is active, so I refactored the code to fix both issues.

PR #4411 will follow up on this commit and add more improvements.

Closes #917
Closes #2963
Closes #4394

@mary-poppins
Copy link

Thanks for the PR!

  • Contributor signed CLA now or in the past
    • If you just signed, leave a comment here with your real name
  • PR's commit messages follow the commit message format
  • Contributor is a certified Pokemon master
  • Contributor unlocked hidden achievement – PR number 4444!

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@@ -760,6 +760,13 @@ function equals(o1, o2) {
}


function csp() {
return (document.securityPolicy && document.securityPolicy.isActive) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we cache this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore that, not a big deal.

@vojtajina
Copy link
Contributor

LGTM

@vojtajina
Copy link
Contributor

The unit tests seem to be broken.

@@ -76,7 +76,7 @@ function $SnifferProvider() {

return eventSupport[event];
},
csp: document.securityPolicy ? document.securityPolicy.isActive : false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tbosch and I looked at this yesterday.  document.securityPolicy appears to be undefined even when the Content-Security-Policy header is present and csp is enabled.  This is on Chrome 29.  So not sure that this fixes it.  We couldn't find a good way to detect csp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the spec says that this is the correct way of doing it: https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html

However, Chrome and others don't seem to support this yet. I like the change of @IgorMinar as it allows to manually override the autodetection and it is quite simple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chirayuk securityPolicy is a CSPv1.1 feature that is not in non-canary Chrome yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha.  Good to know.  Thanks!

When we refactored , we broke the csp mode because the previous implementation
relied on the fact that it was ok to lazy initialize the .csp property, this
is not the case any more.

Besides, we need to know about csp mode during bootstrap and avoid injecting the
stylesheet when csp is active, so I refactored the code to fix both issues.

PR angular#4411 will follow up on this commit and add more improvements.

Closes angular#917
Closes angular#2963
Closes angular#4394
Closes angular#4444

BREAKING CHANGE: triggering ngCsp directive via `ng:csp` attribute is not
supported any more. Please use data-ng-csp instead.
@IgorMinar IgorMinar closed this in 08f376f Oct 19, 2013
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
When we refactored , we broke the csp mode because the previous implementation
relied on the fact that it was ok to lazy initialize the .csp property, this
is not the case any more.

Besides, we need to know about csp mode during bootstrap and avoid injecting the
stylesheet when csp is active, so I refactored the code to fix both issues.

PR angular#4411 will follow up on this commit and add more improvements.

Closes angular#917
Closes angular#2963
Closes angular#4394
Closes angular#4444

BREAKING CHANGE: triggering ngCsp directive via `ng:csp` attribute is not
supported any more. Please use data-ng-csp instead.
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
When we refactored , we broke the csp mode because the previous implementation
relied on the fact that it was ok to lazy initialize the .csp property, this
is not the case any more.

Besides, we need to know about csp mode during bootstrap and avoid injecting the
stylesheet when csp is active, so I refactored the code to fix both issues.

PR angular#4411 will follow up on this commit and add more improvements.

Closes angular#917
Closes angular#2963
Closes angular#4394
Closes angular#4444

BREAKING CHANGE: triggering ngCsp directive via `ng:csp` attribute is not
supported any more. Please use data-ng-csp instead.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants