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

Inconsistent handling of $sce trustedUrl with $http #11328

Closed
klhuillier opened this issue Mar 15, 2015 · 5 comments
Closed

Inconsistent handling of $sce trustedUrl with $http #11328

klhuillier opened this issue Mar 15, 2015 · 5 comments

Comments

@klhuillier
Copy link

// Works:
$http.get($sce.trustAsUrl('/')).success(function(d){$log.log(d);});

// Fails:
$http.get($sce.trustAsUrl('/'), {params: {timestamp: 0}}).success(function(d){$log.log(d);});

In the first case, when the trusted URL reaches the XmlHttpRequest, its toString method is used to get the wrapped URL. In the second case, the buildUrl function attempts to add parameters, but the given URL is not a string as expected.

I feel that the buildUrl function should reject a non-string argument for url in all cases.

@petebacondarwin
Copy link
Contributor

Or perhaps buildUrl should understand and cope with "trusted" resources?

@petebacondarwin
Copy link
Contributor

@pkozlowski-opensource could you take a look at this as part of the buildUrl refactoring?

@klhuillier
Copy link
Author

I thought about suggesting buildUrl tolerate trusted URLs, but I couldn't think of a reason it should. I also can't think of a reason it should not, other than, "is it really necessary?" I would be agreeable to either option.

The main issue was trusted URLs were working some of the time, but failing with an unhelpful message at other times. According to the current documentation, it should be failing every time because url is specified as type string.

chirayuk added a commit to chirayuk/angular.js that referenced this issue Apr 16, 2015
WORK-IN-PROGRESS.  Do **NOT** merge.  More work needs to be done and the tests are currently broken.

- JSONP should require trusted resource URLs.  This would be a breaking
  change but maybe not too onerous since same origin URLs are trusted in
  the default config and you can easily whitelist any 3rd party URLs you
  trust in one single place (your app/module config.)
- fix a bug where $http can't handle $sce wrapper URLs.

Closes angular#11352
Closes angular#11328
@chirayuk
Copy link
Contributor

I have a work in progress PR that will fix this as a side effect of fixing #11352. I started on it yesterday but didn't have time to finish it. I won't get to it anytime today or tomorrow. However, I created a work-in-progress PR to let folks know that some work has started on it.

@chirayuk chirayuk modified the milestones: 1.4.0-rc.1, 1.4.0-rc.2 Apr 24, 2015
@petebacondarwin petebacondarwin modified the milestones: 1.5.x - migration-facilitation, 1.4.0-rc.2 May 5, 2015
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Sep 15, 2016
- JSONP should require trusted resource URLs.  This would be a breaking
  change but maybe not too onerous since same origin URLs are trusted in
  the default config and you can easily whitelist any 3rd party URLs you
  trust in one single place (your app/module config.)
- fix a bug where $http can't handle $sce wrapper URLs.

Closes angular#11352
Closes angular#11328
@petebacondarwin petebacondarwin modified the milestones: 1.6.0, 1.5.x Sep 15, 2016
@petebacondarwin
Copy link
Contributor

In December we put in an explicit check for non-string URLs so that effectively closes this issue.
We are still looking at making JSONP more secure with $sce which might require us to relax that constraint going forward.

petebacondarwin added a commit that referenced this issue Oct 5, 2016
… config

The query parameter that will be used to transmit the JSONP callback to the
server is now specified via the `jsonpCallbackParam` config value, instead of
using the `JSON_CALLBACK` placeholder.

* Any use of `JSON_CALLBACK` in a JSONP request URL will cause an error.
* Any request that provides a parameter with the same name as that given
by the `jsonpCallbackParam` config property will cause an error.

This is to prevent malicious attack via the response from an app inadvertently
allowing untrusted data to be used to generate the callback parameter.

Closes #15161
Closes #15143
Closes #11352
Closes #11328

BREAKING CHANGE

You can no longer use the `JSON_CALLBACK` placeholder in your JSONP requests.
Instead you must provide the name of the query parameter that will pass the
callback via the `jsonpCallbackParam` property of the config object, or app-wide via
the `$http.defaults.jsonpCallbackParam` property, which is `"callback"` by default.

Before this change:

```
$http.json('trusted/url?callback=JSON_CALLBACK');
$http.json('other/trusted/url', {params:cb:'JSON_CALLBACK'});
```

After this change:

```
$http.json('trusted/url');
$http.json('other/trusted/url', {callbackParam:'cb'});
```
ellimist pushed a commit to ellimist/angular.js that referenced this issue Mar 15, 2017
… config

The query parameter that will be used to transmit the JSONP callback to the
server is now specified via the `jsonpCallbackParam` config value, instead of
using the `JSON_CALLBACK` placeholder.

* Any use of `JSON_CALLBACK` in a JSONP request URL will cause an error.
* Any request that provides a parameter with the same name as that given
by the `jsonpCallbackParam` config property will cause an error.

This is to prevent malicious attack via the response from an app inadvertently
allowing untrusted data to be used to generate the callback parameter.

Closes angular#15161
Closes angular#15143
Closes angular#11352
Closes angular#11328

BREAKING CHANGE

You can no longer use the `JSON_CALLBACK` placeholder in your JSONP requests.
Instead you must provide the name of the query parameter that will pass the
callback via the `jsonpCallbackParam` property of the config object, or app-wide via
the `$http.defaults.jsonpCallbackParam` property, which is `"callback"` by default.

Before this change:

```
$http.json('trusted/url?callback=JSON_CALLBACK');
$http.json('other/trusted/url', {params:cb:'JSON_CALLBACK'});
```

After this change:

```
$http.json('trusted/url');
$http.json('other/trusted/url', {callbackParam:'cb'});
```
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.