You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
* // Allow loading from our assets domain. Notice the difference between * and **.
121
+
* 'http://srv*.assets.example.com/**']);
122
+
*
123
+
* // The blacklist overrides the whitelist so the open redirect here is blocked.
124
+
* $sceDelegateProvider.resourceUrlBlacklist([
125
+
* 'http://myapp.example.com/clickThru**']);
126
+
* });
127
+
* </pre>
55
128
*/
56
129
57
130
function$SceDelegateProvider(){
@@ -68,28 +141,25 @@ function $SceDelegateProvider() {
68
141
* @function
69
142
*
70
143
* @param {Array=} whitelist When provided, replaces the resourceUrlWhitelist with the value
71
-
* provided. This must be an array.
72
-
*
73
-
* Each element of this array must either be a regex or the special string `'self'`.
74
-
*
75
-
* When a regex is used, it is matched against the normalized / absolute URL of the resource
76
-
* being tested.
144
+
* provided. This must be an array or null. A snapshot of this array is used so further
145
+
* changes to the array are ignored.
77
146
*
78
-
* The **special string** `'self'` can be used to match against all URLs of the same domain as the
79
-
* application document with the same protocol (allows sourcing https resources from http documents.)
147
+
* Follow {@link ng.$sce#resourceUrlPatternItem this link} for a description of the items allowed in
148
+
* this array.
80
149
*
81
-
* Please note that **an empty whitelist array will block all URLs**!
150
+
* Note: **an empty whitelist array will block all URLs**!
82
151
*
83
152
* @return {Array} the currently set whitelist array.
84
153
*
85
-
* The **default value** when no whitelist has been explicitly set is `['self']`.
154
+
* The **default value** when no whitelist has been explicitly set is `['self']` allowing only
155
+
* same origin resource requests.
86
156
*
87
157
* @description
88
158
* Sets/Gets the whitelist of trusted resource URLs.
89
159
*/
90
160
this.resourceUrlWhitelist=function(value){
91
161
if(arguments.length){
92
-
resourceUrlWhitelist=value;
162
+
resourceUrlWhitelist=adjustMatchers(value);
93
163
}
94
164
returnresourceUrlWhitelist;
95
165
};
@@ -101,13 +171,11 @@ function $SceDelegateProvider() {
101
171
* @function
102
172
*
103
173
* @param {Array=} blacklist When provided, replaces the resourceUrlBlacklist with the value
104
-
* provided. This must be an array.
174
+
* provided. This must be an array or null. A snapshot of this array is used so further
175
+
* changes to the array are ignored.
105
176
*
106
-
* Each element of this array must either be a regex or the special string `'self'` (see
107
-
* `resourceUrlWhitelist` for meaning - it's only really useful there.)
108
-
*
109
-
* When a regex is used, it is matched against the normalized / absolute URL of the resource
110
-
* being tested.
177
+
* Follow {@link ng.$sce#resourceUrlPatternItem this link} for a description of the items allowed in
178
+
* this array.
111
179
*
112
180
* The typical usage for the blacklist is to **block [open redirects](http://cwe.mitre.org/data/definitions/601.html)**
113
181
* served by your domain as these would otherwise be trusted but actually return content from the redirected
@@ -126,7 +194,7 @@ function $SceDelegateProvider() {
126
194
127
195
this.resourceUrlBlacklist=function(value){
128
196
if(arguments.length){
129
-
resourceUrlBlacklist=value;
197
+
resourceUrlBlacklist=adjustMatchers(value);
130
198
}
131
199
returnresourceUrlBlacklist;
132
200
};
@@ -147,7 +215,8 @@ function $SceDelegateProvider() {
147
215
if(matcher==='self'){
148
216
return$$urlUtils.isSameOrigin(parsedUrl);
149
217
}else{
150
-
return!!parsedUrl.href.match(matcher);
218
+
// definitely a regex. See adjustMatchers()
219
+
return!!matcher.exec(parsedUrl.href);
151
220
}
152
221
}
153
222
@@ -457,9 +526,54 @@ function $SceDelegateProvider() {
457
526
* | `$sce.RESOURCE_URL` | For URLs that are not only safe to follow as links, but whose contens are also safe to include in your application. Examples include `ng-include`, `src` / `ngSrc` bindings for tags other than `IMG` (e.g. `IFRAME`, `OBJECT`, etc.) <br><br>Note that `$sce.RESOURCE_URL` makes a stronger statement about the URL than `$sce.URL` does and therefore contexts requiring values trusted for `$sce.RESOURCE_URL` can be used anywhere that values trusted for `$sce.URL` are required. |
458
527
* | `$sce.JS` | For JavaScript that is safe to execute in your application's context. Currently unused. Feel free to use it in your own directives. |
459
528
*
460
-
* ## Show me an example.
529
+
* ## Format of items in {@link ng.$sceDelegateProvider#resourceUrlWhitelist resourceUrlWhitelist}/{@link ng.$sceDelegateProvider#resourceUrlBlacklist Blacklist} <a name="resourceUrlPatternItem"></a>
530
+
*
531
+
* Each element in these arrays must be one of the following:
532
+
*
533
+
* - **'self'**
534
+
* - The special **string**, `'self'`, can be used to match against all URLs of the **same
535
+
* domain** as the application document using the **same protocol**.
536
+
* - **String** (except the special value `'self'`)
537
+
* - The string is matched against the full *normalized / absolute URL* of the resource
538
+
* being tested (substring matches are not good enough.)
539
+
* - There are exactly **two wildcard sequences** - `*` and `**`. All other characters
540
+
* match themselves.
541
+
* - `*`: matches zero or more occurances of any character other than one of the following 6
542
+
* characters: '`:`', '`/`', '`.`', '`?`', '`&`' and ';'. It's a useful wildcard for use
543
+
* in a whitelist.
544
+
* - `**`: matches zero or more occurances of *any* character. As such, it's not
545
+
* not appropriate to use in for a scheme, domain, etc. as it would match too much. (e.g.
546
+
* http://**.example.com/ would match http://evil.com/?ignore=.example.com/ and that might
547
+
* not have been the intention.) It's usage at the very end of the path is ok. (e.g.
548
+
* http://foo.example.com/templates/**).
549
+
* - **RegExp** (*see caveat below*)
550
+
* - *Caveat*: While regular expressions are powerful and offer great flexibility, their syntax
551
+
* (and all the inevitable escaping) makes them *harder to maintain*. It's easy to
552
+
* accidentally introduce a bug when one updates a complex expression (imho, all regexes should
553
+
* have good test coverage.). For instance, the use of `.` in the regex is correct only in a
554
+
* small number of cases. A `.` character in the regex used when matching the scheme or a
555
+
* subdomain could be matched against a `:` or literal `.` that was likely not intended. It
556
+
* is highly recommended to use the string patterns and only fall back to regular expressions
557
+
* if they as a last resort.
558
+
* - The regular expression must be an instance of RegExp (i.e. not a string.) It is
559
+
* matched against the **entire** *normalized / absolute URL* of the resource being tested
560
+
* (even when the RegExp did not have the `^` and `$` codes.) In addition, any flags
561
+
* present on the RegExp (such as multiline, global, ignoreCase) are ignored.
562
+
* - If you are generating your Javascript from some other templating engine (not
563
+
* recommended, e.g. in issue [#4006](https://github.com/angular/angular.js/issues/4006)),
564
+
* remember to escape your regular expression (and be aware that you might need more than
565
+
* one level of escaping depending on your templating engine and the way you interpolated
566
+
* the value.) Do make use of your platform's escaping mechanism as it might be good
0 commit comments