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

Module#run methods are run before ng-csp takes effect #2963

Closed
boushley opened this issue Jun 13, 2013 · 12 comments
Closed

Module#run methods are run before ng-csp takes effect #2963

boushley opened this issue Jun 13, 2013 · 12 comments

Comments

@boushley
Copy link

Right now if I have a module.run() that triggers the getterFn logic inside of Angular it is occuring before the ng-csp directive can take effect. So the Function constructor function is returned and used, and the initialization stops form the CSP error.

I'm able to work around this for now by adding another module.run method prior that has the $sniffer injected and sets $sniffer.csp to true.

It would be great if the module.run methods were invoked after ng-csp took effect. Alternatively it seems like it would be better to inject the $snifferProvider into the module config and be able to tell it to turn on CSP.

Is there a suggested direction for how you would want to solve this?

@lanterndev
Copy link
Contributor

I also just hit this. Ping @mhevery @IgorMinar @btford et al. can this be triaged?

@boushley
Copy link
Author

I ended up using a decorator to get this working instead of a run method, but it would be great to do something around this.

@lanterndev
Copy link
Contributor

@boushley Would you be able to share a link to your decorator?

@boushley
Copy link
Author

I just used:

$provide.decorator('$sniffer', ['$delegate', function ($sniffer) {
    $sniffer.csp = true;
    return $sniffer;
}]);

@lanterndev
Copy link
Contributor

Thanks a lot @boushley, that did the trick for me too.

@digitarald
Copy link

This is still broken by default and I couldn't get it working with the decorator patch posted above? Any plans to fix ngCSP to work? I am just starting and don't have a great understanding of the inner workings yet.

@lanterndev
Copy link
Contributor

@digitarald you have to put the snippet above inside a config function like this:

angular.module('yourModule')
  .config(function ($provide) {
    $provide.decorator('$sniffer', ['$delegate', function ($sniffer) {
      $sniffer.csp = true;
      return $sniffer;
    }]);
  })

Hope this helps.

@digitarald
Copy link

@Skivvies thank you, that worked after all. But it still defeats the purpose of ng-csp; which obviously isn't working.

@boushley
Copy link
Author

boushley commented Aug 8, 2013

I wasn't (and I don't think @Skivvies was) suggesting that the decorator workaround is a solution. It's just a workaround until something in angular get's changed. If you look at the code for $sniffer it says it's internal and to keep your hands off, essentially, but this works for now.

@digitarald
Copy link

No blaming intended on my side! I am glad the workaround is working for now, even though it uses internals and isn't future proof. I just wanted raise awareness and priority for this bug which renders ng-csp ineffective.

@boushley
Copy link
Author

boushley commented Aug 8, 2013

My guess is that this is going to be a tough cookie to solve. I've been reading through some of the Angular internals and it might be pretty hard to get this ordered correctly.

@thenikso
Copy link
Contributor

I'm trying to use http://developer.chrome.com/apps with 1.2.0-rc.3 and I'm having this issue.

Maybe just check for ng-csp attribute much like the ng-app gets checked instead of using a directive?

IgorMinar added a commit to IgorMinar/angular.js that referenced this issue Oct 19, 2013
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 issue 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 issue 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
Development

Successfully merging a pull request may close this issue.

4 participants