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

ngCsp example in docs doesn't work #16270

Closed
Narretz opened this issue Oct 12, 2017 · 4 comments
Closed

ngCsp example in docs doesn't work #16270

Narretz opened this issue Oct 12, 2017 · 4 comments

Comments

@Narretz
Copy link
Contributor

Narretz commented Oct 12, 2017

See https://code.angularjs.org/snapshot/docs/api/ng/directive/ngCsp#examples

You can do eval even though it should be disallowed. The e2e tests don't fail though.

@Narretz Narretz added this to the Backlog milestone Oct 12, 2017
@petebacondarwin
Copy link
Contributor

Is that because we are not turning CSP on via the server for that page?

@Narretz
Copy link
Contributor Author

Narretz commented Oct 13, 2017

I actually don't know what that means 😱
We only set the ng-csp attribute on the html or body tag.

@petebacondarwin
Copy link
Contributor

petebacondarwin commented Oct 13, 2017

OK, so I actually took a look at the example :-)
The point of ng-csp is to tell AngularJS not to do anything that might trigger a CSP error. It does not "turn on" CSP protection for the application. That must be done by other settings outside of AngularJS.
What developers do in their own controllers is not affected by the ng-csp directive.

So this example is rather misleading, IMO, since the evil function will be called and will execute quite happily on a browser that does not have CSP turned on - whether or not ng-csp is there.

If we could setup the example so that the browser really does turn on CSP (https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP#Using_CSP) then it might make more sense.

@Narretz
Copy link
Contributor Author

Narretz commented Oct 13, 2017

Ah, that makes sense:
There's a note in the example:
<!-- Note: the .csp suffix in the example name triggers CSP mode in our http server! -->

I assume this was lost during some docs migration.

However, the example was not rendered / tested because the indentation was wrong, so it's unclear if this actually worked.

Narretz added a commit to Narretz/angular.js that referenced this issue Feb 23, 2018
Narretz added a commit to Narretz/angular.js that referenced this issue Feb 23, 2018
Narretz added a commit to Narretz/angular.js that referenced this issue Mar 1, 2018
@Narretz Narretz closed this as completed in 4f4ad3c Mar 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants