@angular-wave/angular.ts 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/.eslintrc.cjs +29 -0
- package/.github/workflows/playwright.yml +27 -0
- package/CHANGELOG.md +17974 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/CONTRIBUTING.md +246 -0
- package/DEVELOPERS.md +488 -0
- package/LICENSE +22 -0
- package/Makefile +31 -0
- package/README.md +115 -0
- package/RELEASE.md +98 -0
- package/SECURITY.md +16 -0
- package/TRIAGING.md +135 -0
- package/css/angular.css +22 -0
- package/dist/angular-ts.cjs.js +36843 -0
- package/dist/angular-ts.esm.js +36841 -0
- package/dist/angular-ts.umd.js +36848 -0
- package/dist/build/angular-animate.js +4272 -0
- package/dist/build/angular-aria.js +426 -0
- package/dist/build/angular-message-format.js +1072 -0
- package/dist/build/angular-messages.js +829 -0
- package/dist/build/angular-mocks.js +3757 -0
- package/dist/build/angular-parse-ext.js +1275 -0
- package/dist/build/angular-resource.js +911 -0
- package/dist/build/angular-route.js +1266 -0
- package/dist/build/angular-sanitize.js +891 -0
- package/dist/build/angular-touch.js +368 -0
- package/dist/build/angular.js +36600 -0
- package/e2e/unit.spec.ts +15 -0
- package/images/android-chrome-192x192.png +0 -0
- package/images/android-chrome-512x512.png +0 -0
- package/images/apple-touch-icon.png +0 -0
- package/images/favicon-16x16.png +0 -0
- package/images/favicon-32x32.png +0 -0
- package/images/favicon.ico +0 -0
- package/images/site.webmanifest +1 -0
- package/index.html +104 -0
- package/package.json +47 -0
- package/playwright.config.ts +78 -0
- package/public/circle.html +1 -0
- package/public/my_child_directive.html +1 -0
- package/public/my_directive.html +1 -0
- package/public/my_other_directive.html +1 -0
- package/public/test.html +1 -0
- package/rollup.config.js +31 -0
- package/src/animations/animateCache.js +55 -0
- package/src/animations/animateChildrenDirective.js +105 -0
- package/src/animations/animateCss.js +1139 -0
- package/src/animations/animateCssDriver.js +291 -0
- package/src/animations/animateJs.js +367 -0
- package/src/animations/animateJsDriver.js +67 -0
- package/src/animations/animateQueue.js +851 -0
- package/src/animations/animation.js +506 -0
- package/src/animations/module.js +779 -0
- package/src/animations/ngAnimateSwap.js +119 -0
- package/src/animations/rafScheduler.js +50 -0
- package/src/animations/shared.js +378 -0
- package/src/constants.js +20 -0
- package/src/core/animate.js +845 -0
- package/src/core/animateCss.js +73 -0
- package/src/core/animateRunner.js +195 -0
- package/src/core/attributes.js +199 -0
- package/src/core/cache.js +45 -0
- package/src/core/compile.js +4727 -0
- package/src/core/controller.js +225 -0
- package/src/core/exceptionHandler.js +63 -0
- package/src/core/filter.js +146 -0
- package/src/core/interpolate.js +442 -0
- package/src/core/interval.js +188 -0
- package/src/core/intervalFactory.js +57 -0
- package/src/core/location.js +1086 -0
- package/src/core/parser/parse.js +2562 -0
- package/src/core/parser/parse.md +13 -0
- package/src/core/q.js +746 -0
- package/src/core/rootScope.js +1596 -0
- package/src/core/sanitizeUri.js +85 -0
- package/src/core/sce.js +1161 -0
- package/src/core/taskTrackerFactory.js +125 -0
- package/src/core/timeout.js +121 -0
- package/src/core/urlUtils.js +187 -0
- package/src/core/utils.js +1349 -0
- package/src/directive/a.js +37 -0
- package/src/directive/attrs.js +283 -0
- package/src/directive/bind.js +51 -0
- package/src/directive/bind.md +142 -0
- package/src/directive/change.js +12 -0
- package/src/directive/change.md +25 -0
- package/src/directive/cloak.js +12 -0
- package/src/directive/cloak.md +24 -0
- package/src/directive/events.js +75 -0
- package/src/directive/events.md +166 -0
- package/src/directive/form.js +725 -0
- package/src/directive/init.js +15 -0
- package/src/directive/init.md +41 -0
- package/src/directive/input.js +1783 -0
- package/src/directive/list.js +46 -0
- package/src/directive/list.md +22 -0
- package/src/directive/ngClass.js +249 -0
- package/src/directive/ngController.js +64 -0
- package/src/directive/ngCsp.js +82 -0
- package/src/directive/ngIf.js +134 -0
- package/src/directive/ngInclude.js +217 -0
- package/src/directive/ngModel.js +1356 -0
- package/src/directive/ngModelOptions.js +509 -0
- package/src/directive/ngOptions.js +670 -0
- package/src/directive/ngRef.js +90 -0
- package/src/directive/ngRepeat.js +650 -0
- package/src/directive/ngShowHide.js +255 -0
- package/src/directive/ngSwitch.js +178 -0
- package/src/directive/ngTransclude.js +98 -0
- package/src/directive/non-bindable.js +11 -0
- package/src/directive/non-bindable.md +17 -0
- package/src/directive/script.js +30 -0
- package/src/directive/select.js +624 -0
- package/src/directive/style.js +25 -0
- package/src/directive/style.md +23 -0
- package/src/directive/validators.js +329 -0
- package/src/exts/aria.js +544 -0
- package/src/exts/messages.js +852 -0
- package/src/filters/filter.js +207 -0
- package/src/filters/filter.md +69 -0
- package/src/filters/filters.js +239 -0
- package/src/filters/json.md +16 -0
- package/src/filters/limit-to.js +43 -0
- package/src/filters/limit-to.md +19 -0
- package/src/filters/order-by.js +183 -0
- package/src/filters/order-by.md +83 -0
- package/src/index.js +13 -0
- package/src/injector.js +1034 -0
- package/src/jqLite.js +1117 -0
- package/src/loader.js +1320 -0
- package/src/public.js +215 -0
- package/src/routeToRegExp.js +41 -0
- package/src/services/anchorScroll.js +135 -0
- package/src/services/browser.js +321 -0
- package/src/services/cacheFactory.js +398 -0
- package/src/services/cookieReader.js +72 -0
- package/src/services/document.js +64 -0
- package/src/services/http.js +1537 -0
- package/src/services/httpBackend.js +206 -0
- package/src/services/log.js +160 -0
- package/src/services/templateRequest.js +139 -0
- package/test/angular.spec.js +2153 -0
- package/test/aria/aria.spec.js +1245 -0
- package/test/binding.spec.js +504 -0
- package/test/build-test.html +14 -0
- package/test/injector.spec.js +2327 -0
- package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
- package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
- package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
- package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
- package/test/jasmine/jasmine-browser.json +17 -0
- package/test/jasmine/jasmine.json +9 -0
- package/test/jqlite.spec.js +2133 -0
- package/test/loader.spec.js +219 -0
- package/test/messages/messages.spec.js +1146 -0
- package/test/min-err.spec.js +174 -0
- package/test/mock-test.html +13 -0
- package/test/module-test.html +15 -0
- package/test/ng/anomate.spec.js +606 -0
- package/test/ng/cache-factor.spec.js +334 -0
- package/test/ng/compile.spec.js +17956 -0
- package/test/ng/controller-provider.spec.js +227 -0
- package/test/ng/cookie-reader.spec.js +98 -0
- package/test/ng/directive/a.spec.js +192 -0
- package/test/ng/directive/bind.spec.js +334 -0
- package/test/ng/directive/boolean.spec.js +136 -0
- package/test/ng/directive/change.spec.js +71 -0
- package/test/ng/directive/class.spec.js +858 -0
- package/test/ng/directive/click.spec.js +38 -0
- package/test/ng/directive/cloak.spec.js +44 -0
- package/test/ng/directive/constoller.spec.js +194 -0
- package/test/ng/directive/element-style.spec.js +92 -0
- package/test/ng/directive/event.spec.js +282 -0
- package/test/ng/directive/form.spec.js +1518 -0
- package/test/ng/directive/href.spec.js +143 -0
- package/test/ng/directive/if.spec.js +402 -0
- package/test/ng/directive/include.spec.js +828 -0
- package/test/ng/directive/init.spec.js +68 -0
- package/test/ng/directive/input.spec.js +3810 -0
- package/test/ng/directive/list.spec.js +170 -0
- package/test/ng/directive/model-options.spec.js +1008 -0
- package/test/ng/directive/model.spec.js +1905 -0
- package/test/ng/directive/non-bindable.spec.js +55 -0
- package/test/ng/directive/options.spec.js +3583 -0
- package/test/ng/directive/ref.spec.js +575 -0
- package/test/ng/directive/repeat.spec.js +1675 -0
- package/test/ng/directive/script.spec.js +52 -0
- package/test/ng/directive/scrset.spec.js +67 -0
- package/test/ng/directive/select.spec.js +2541 -0
- package/test/ng/directive/show-hide.spec.js +253 -0
- package/test/ng/directive/src.spec.js +157 -0
- package/test/ng/directive/style.spec.js +178 -0
- package/test/ng/directive/switch.spec.js +647 -0
- package/test/ng/directive/validators.spec.js +717 -0
- package/test/ng/document.spec.js +52 -0
- package/test/ng/filter/filter.spec.js +714 -0
- package/test/ng/filter/filters.spec.js +35 -0
- package/test/ng/filter/limit-to.spec.js +251 -0
- package/test/ng/filter/order-by.spec.js +891 -0
- package/test/ng/filter.spec.js +149 -0
- package/test/ng/http-backend.spec.js +398 -0
- package/test/ng/http.spec.js +4071 -0
- package/test/ng/interpolate.spec.js +642 -0
- package/test/ng/interval.spec.js +343 -0
- package/test/ng/location.spec.js +3488 -0
- package/test/ng/on.spec.js +229 -0
- package/test/ng/parse.spec.js +4655 -0
- package/test/ng/prop.spec.js +805 -0
- package/test/ng/q.spec.js +2904 -0
- package/test/ng/root-element.spec.js +16 -0
- package/test/ng/sanitize-uri.spec.js +249 -0
- package/test/ng/sce.spec.js +660 -0
- package/test/ng/scope.spec.js +3442 -0
- package/test/ng/template-request.spec.js +236 -0
- package/test/ng/timeout.spec.js +351 -0
- package/test/ng/url-utils.spec.js +156 -0
- package/test/ng/utils.spec.js +144 -0
- package/test/original-test.html +21 -0
- package/test/public.spec.js +34 -0
- package/test/sanitize/bing-html.spec.js +36 -0
- package/test/server/express.js +158 -0
- package/test/test-utils.js +11 -0
- package/tsconfig.json +17 -0
- package/types/angular.d.ts +138 -0
- package/types/global.d.ts +9 -0
- package/types/index.d.ts +2357 -0
- package/types/jqlite.d.ts +558 -0
- package/vite.config.js +14 -0
package/src/core/sce.js
ADDED
|
@@ -0,0 +1,1161 @@
|
|
|
1
|
+
import {
|
|
2
|
+
urlIsSameOrigin,
|
|
3
|
+
urlIsSameOriginAsBaseUrl,
|
|
4
|
+
urlResolve,
|
|
5
|
+
} from "./urlUtils";
|
|
6
|
+
import {
|
|
7
|
+
forEach,
|
|
8
|
+
isDefined,
|
|
9
|
+
isFunction,
|
|
10
|
+
isRegExp,
|
|
11
|
+
isString,
|
|
12
|
+
isUndefined,
|
|
13
|
+
lowercase,
|
|
14
|
+
minErr,
|
|
15
|
+
shallowCopy,
|
|
16
|
+
} from "./utils";
|
|
17
|
+
|
|
18
|
+
import { snakeToCamel } from "../jqLite";
|
|
19
|
+
|
|
20
|
+
const $sceMinErr = minErr("$sce");
|
|
21
|
+
|
|
22
|
+
export const SCE_CONTEXTS = {
|
|
23
|
+
// HTML is used when there's HTML rendered (e.g. ng-bind-html, iframe srcdoc binding).
|
|
24
|
+
HTML: "html",
|
|
25
|
+
|
|
26
|
+
// Style statements or stylesheets. Currently unused in AngularJS.
|
|
27
|
+
CSS: "css",
|
|
28
|
+
|
|
29
|
+
// An URL used in a context where it refers to the source of media, which are not expected to be run
|
|
30
|
+
// as scripts, such as an image, audio, video, etc.
|
|
31
|
+
MEDIA_URL: "mediaUrl",
|
|
32
|
+
|
|
33
|
+
// An URL used in a context where it does not refer to a resource that loads code.
|
|
34
|
+
// A value that can be trusted as a URL can also trusted as a MEDIA_URL.
|
|
35
|
+
URL: "url",
|
|
36
|
+
|
|
37
|
+
// RESOURCE_URL is a subtype of URL used where the referred-to resource could be interpreted as
|
|
38
|
+
// code. (e.g. ng-include, script src binding, templateUrl)
|
|
39
|
+
// A value that can be trusted as a RESOURCE_URL, can also trusted as a URL and a MEDIA_URL.
|
|
40
|
+
RESOURCE_URL: "resourceUrl",
|
|
41
|
+
|
|
42
|
+
// Script. Currently unused in AngularJS.
|
|
43
|
+
JS: "js",
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// Copied from:
|
|
47
|
+
// http://docs.closure-library.googlecode.com/git/local_closure_goog_string_string.js.source.html#line1021
|
|
48
|
+
// Prereq: s is a string.
|
|
49
|
+
export function escapeForRegexp(s) {
|
|
50
|
+
return (
|
|
51
|
+
s
|
|
52
|
+
.replace(/([-()[\]{}+?*.$^|,:#<!\\])/g, "\\$1")
|
|
53
|
+
// eslint-disable-next-line no-control-regex
|
|
54
|
+
.replace(/\x08/g, "\\x08")
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function adjustMatcher(matcher) {
|
|
59
|
+
if (matcher === "self") {
|
|
60
|
+
return matcher;
|
|
61
|
+
}
|
|
62
|
+
if (isString(matcher)) {
|
|
63
|
+
// Strings match exactly except for 2 wildcards - '*' and '**'.
|
|
64
|
+
// '*' matches any character except those from the set ':/.?&'.
|
|
65
|
+
// '**' matches any character (like .* in a RegExp).
|
|
66
|
+
// More than 2 *'s raises an error as it's ill defined.
|
|
67
|
+
if (matcher.indexOf("***") > -1) {
|
|
68
|
+
throw $sceMinErr(
|
|
69
|
+
"iwcard",
|
|
70
|
+
"Illegal sequence *** in string matcher. String: {0}",
|
|
71
|
+
matcher,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
matcher = escapeForRegexp(matcher)
|
|
75
|
+
.replace(/\\\*\\\*/g, ".*")
|
|
76
|
+
.replace(/\\\*/g, "[^:/.?&;]*");
|
|
77
|
+
return new RegExp(`^${matcher}$`);
|
|
78
|
+
}
|
|
79
|
+
if (isRegExp(matcher)) {
|
|
80
|
+
// The only other type of matcher allowed is a Regexp.
|
|
81
|
+
// Match entire URL / disallow partial matches.
|
|
82
|
+
// Flags are reset (i.e. no global, ignoreCase or multiline)
|
|
83
|
+
return new RegExp(`^${matcher.source}$`);
|
|
84
|
+
}
|
|
85
|
+
throw $sceMinErr(
|
|
86
|
+
"imatcher",
|
|
87
|
+
'Matchers may only be "self", string patterns or RegExp objects',
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function adjustMatchers(matchers) {
|
|
92
|
+
const adjustedMatchers = [];
|
|
93
|
+
if (isDefined(matchers)) {
|
|
94
|
+
forEach(matchers, (matcher) => {
|
|
95
|
+
adjustedMatchers.push(adjustMatcher(matcher));
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return adjustedMatchers;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @ngdoc service
|
|
103
|
+
* @name $sceDelegate
|
|
104
|
+
* @kind function
|
|
105
|
+
*
|
|
106
|
+
* @description
|
|
107
|
+
*
|
|
108
|
+
* `$sceDelegate` is a service that is used by the `$sce` service to provide {@link ng.$sce Strict
|
|
109
|
+
* Contextual Escaping (SCE)} services to AngularJS.
|
|
110
|
+
*
|
|
111
|
+
* For an overview of this service and the functionnality it provides in AngularJS, see the main
|
|
112
|
+
* page for {@link ng.$sce SCE}. The current page is targeted for developers who need to alter how
|
|
113
|
+
* SCE works in their application, which shouldn't be needed in most cases.
|
|
114
|
+
*
|
|
115
|
+
* <div class="alert alert-danger">
|
|
116
|
+
* AngularJS strongly relies on contextual escaping for the security of bindings: disabling or
|
|
117
|
+
* modifying this might cause cross site scripting (XSS) vulnerabilities. For libraries owners,
|
|
118
|
+
* changes to this service will also influence users, so be extra careful and document your changes.
|
|
119
|
+
* </div>
|
|
120
|
+
*
|
|
121
|
+
* Typically, you would configure or override the {@link ng.$sceDelegate $sceDelegate} instead of
|
|
122
|
+
* the `$sce` service to customize the way Strict Contextual Escaping works in AngularJS. This is
|
|
123
|
+
* because, while the `$sce` provides numerous shorthand methods, etc., you really only need to
|
|
124
|
+
* override 3 core functions (`trustAs`, `getTrusted` and `valueOf`) to replace the way things
|
|
125
|
+
* work because `$sce` delegates to `$sceDelegate` for these operations.
|
|
126
|
+
*
|
|
127
|
+
* Refer {@link ng.$sceDelegateProvider $sceDelegateProvider} to configure this service.
|
|
128
|
+
*
|
|
129
|
+
* The default instance of `$sceDelegate` should work out of the box with little pain. While you
|
|
130
|
+
* can override it completely to change the behavior of `$sce`, the common case would
|
|
131
|
+
* involve configuring the {@link ng.$sceDelegateProvider $sceDelegateProvider} instead by setting
|
|
132
|
+
* your own trusted and banned resource lists for trusting URLs used for loading AngularJS resources
|
|
133
|
+
* such as templates. Refer {@link ng.$sceDelegateProvider#trustedResourceUrlList
|
|
134
|
+
* $sceDelegateProvider.trustedResourceUrlList} and {@link
|
|
135
|
+
* ng.$sceDelegateProvider#bannedResourceUrlList $sceDelegateProvider.bannedResourceUrlList}
|
|
136
|
+
*/
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @ngdoc provider
|
|
140
|
+
* @name $sceDelegateProvider
|
|
141
|
+
*
|
|
142
|
+
*
|
|
143
|
+
* @description
|
|
144
|
+
*
|
|
145
|
+
* The `$sceDelegateProvider` provider allows developers to configure the {@link ng.$sceDelegate
|
|
146
|
+
* $sceDelegate service}, used as a delegate for {@link ng.$sce Strict Contextual Escaping (SCE)}.
|
|
147
|
+
*
|
|
148
|
+
* The `$sceDelegateProvider` allows one to get/set the `trustedResourceUrlList` and
|
|
149
|
+
* `bannedResourceUrlList` used to ensure that the URLs used for sourcing AngularJS templates and
|
|
150
|
+
* other script-running URLs are safe (all places that use the `$sce.RESOURCE_URL` context). See
|
|
151
|
+
* {@link ng.$sceDelegateProvider#trustedResourceUrlList
|
|
152
|
+
* $sceDelegateProvider.trustedResourceUrlList} and
|
|
153
|
+
* {@link ng.$sceDelegateProvider#bannedResourceUrlList $sceDelegateProvider.bannedResourceUrlList},
|
|
154
|
+
*
|
|
155
|
+
* For the general details about this service in AngularJS, read the main page for {@link ng.$sce
|
|
156
|
+
* Strict Contextual Escaping (SCE)}.
|
|
157
|
+
*
|
|
158
|
+
* **Example**: Consider the following case. <a name="example"></a>
|
|
159
|
+
*
|
|
160
|
+
* - your app is hosted at url `http://myapp.example.com/`
|
|
161
|
+
* - but some of your templates are hosted on other domains you control such as
|
|
162
|
+
* `http://srv01.assets.example.com/`, `http://srv02.assets.example.com/`, etc.
|
|
163
|
+
* - and you have an open redirect at `http://myapp.example.com/clickThru?...`.
|
|
164
|
+
*
|
|
165
|
+
* Here is what a secure configuration for this scenario might look like:
|
|
166
|
+
*
|
|
167
|
+
* ```
|
|
168
|
+
* angular.module('myApp', []).config(function($sceDelegateProvider) {
|
|
169
|
+
* $sceDelegateProvider.trustedResourceUrlList([
|
|
170
|
+
* // Allow same origin resource loads.
|
|
171
|
+
* 'self',
|
|
172
|
+
* // Allow loading from our assets domain. Notice the difference between * and **.
|
|
173
|
+
* 'http://srv*.assets.example.com/**'
|
|
174
|
+
* ]);
|
|
175
|
+
*
|
|
176
|
+
* // The banned resource URL list overrides the trusted resource URL list so the open redirect
|
|
177
|
+
* // here is blocked.
|
|
178
|
+
* $sceDelegateProvider.bannedResourceUrlList([
|
|
179
|
+
* 'http://myapp.example.com/clickThru**'
|
|
180
|
+
* ]);
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
* Note that an empty trusted resource URL list will block every resource URL from being loaded, and will require
|
|
184
|
+
* you to manually mark each one as trusted with `$sce.trustAsResourceUrl`. However, templates
|
|
185
|
+
* requested by {@link ng.$templateRequest $templateRequest} that are present in
|
|
186
|
+
* {@link ng.$templateCache $templateCache} will not go through this check. If you have a mechanism
|
|
187
|
+
* to populate your templates in that cache at config time, then it is a good idea to remove 'self'
|
|
188
|
+
* from the trusted resource URL lsit. This helps to mitigate the security impact of certain types
|
|
189
|
+
* of issues, like for instance attacker-controlled `ng-includes`.
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
export function $SceDelegateProvider() {
|
|
193
|
+
this.SCE_CONTEXTS = SCE_CONTEXTS;
|
|
194
|
+
|
|
195
|
+
// Resource URLs can also be trusted by policy.
|
|
196
|
+
let trustedResourceUrlList = ["self"];
|
|
197
|
+
let bannedResourceUrlList = [];
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @ngdoc method
|
|
201
|
+
* @name $sceDelegateProvider#trustedResourceUrlList
|
|
202
|
+
* @kind function
|
|
203
|
+
*
|
|
204
|
+
* @param {Array=} trustedResourceUrlList When provided, replaces the trustedResourceUrlList with
|
|
205
|
+
* the value provided. This must be an array or null. A snapshot of this array is used so
|
|
206
|
+
* further changes to the array are ignored.
|
|
207
|
+
* Follow {@link ng.$sce#resourceUrlPatternItem this link} for a description of the items
|
|
208
|
+
* allowed in this array.
|
|
209
|
+
*
|
|
210
|
+
* @return {Array} The currently set trusted resource URL array.
|
|
211
|
+
*
|
|
212
|
+
* @description
|
|
213
|
+
* Sets/Gets the list trusted of resource URLs.
|
|
214
|
+
*
|
|
215
|
+
* The **default value** when no `trustedResourceUrlList` has been explicitly set is `['self']`
|
|
216
|
+
* allowing only same origin resource requests.
|
|
217
|
+
*
|
|
218
|
+
* <div class="alert alert-warning">
|
|
219
|
+
* **Note:** the default `trustedResourceUrlList` of 'self' is not recommended if your app shares
|
|
220
|
+
* its origin with other apps! It is a good idea to limit it to only your application's directory.
|
|
221
|
+
* </div>
|
|
222
|
+
*/
|
|
223
|
+
this.trustedResourceUrlList = function (value) {
|
|
224
|
+
if (arguments.length) {
|
|
225
|
+
trustedResourceUrlList = adjustMatchers(value);
|
|
226
|
+
}
|
|
227
|
+
return trustedResourceUrlList;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* @ngdoc method
|
|
232
|
+
* @name $sceDelegateProvider#bannedResourceUrlList
|
|
233
|
+
* @kind function
|
|
234
|
+
*
|
|
235
|
+
* @param {Array=} bannedResourceUrlList When provided, replaces the `bannedResourceUrlList` with
|
|
236
|
+
* the value provided. This must be an array or null. A snapshot of this array is used so
|
|
237
|
+
* further changes to the array are ignored.</p><p>
|
|
238
|
+
* Follow {@link ng.$sce#resourceUrlPatternItem this link} for a description of the items
|
|
239
|
+
* allowed in this array.</p><p>
|
|
240
|
+
* The typical usage for the `bannedResourceUrlList` is to **block
|
|
241
|
+
* [open redirects](http://cwe.mitre.org/data/definitions/601.html)** served by your domain as
|
|
242
|
+
* these would otherwise be trusted but actually return content from the redirected domain.
|
|
243
|
+
* </p><p>
|
|
244
|
+
* Finally, **the banned resource URL list overrides the trusted resource URL list** and has
|
|
245
|
+
* the final say.
|
|
246
|
+
*
|
|
247
|
+
* @return {Array} The currently set `bannedResourceUrlList` array.
|
|
248
|
+
*
|
|
249
|
+
* @description
|
|
250
|
+
* Sets/Gets the `bannedResourceUrlList` of trusted resource URLs.
|
|
251
|
+
*
|
|
252
|
+
* The **default value** when no trusted resource URL list has been explicitly set is the empty
|
|
253
|
+
* array (i.e. there is no `bannedResourceUrlList`.)
|
|
254
|
+
*/
|
|
255
|
+
this.bannedResourceUrlList = function (value) {
|
|
256
|
+
if (arguments.length) {
|
|
257
|
+
bannedResourceUrlList = adjustMatchers(value);
|
|
258
|
+
}
|
|
259
|
+
return bannedResourceUrlList;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
this.$get = [
|
|
263
|
+
"$injector",
|
|
264
|
+
"$$sanitizeUri",
|
|
265
|
+
|
|
266
|
+
function ($injector, $$sanitizeUri) {
|
|
267
|
+
let htmlSanitizer = function () {
|
|
268
|
+
throw $sceMinErr(
|
|
269
|
+
"unsafe",
|
|
270
|
+
"Attempting to use an unsafe value in a safe context.",
|
|
271
|
+
);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
if ($injector.has("$sanitize")) {
|
|
275
|
+
htmlSanitizer = $injector.get("$sanitize");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function matchUrl(matcher, parsedUrl) {
|
|
279
|
+
if (matcher === "self") {
|
|
280
|
+
return (
|
|
281
|
+
urlIsSameOrigin(parsedUrl) || urlIsSameOriginAsBaseUrl(parsedUrl)
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
// definitely a regex. See adjustMatchers()
|
|
285
|
+
return !!matcher.exec(parsedUrl.href);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function isResourceUrlAllowedByPolicy(url) {
|
|
289
|
+
const parsedUrl = urlResolve(url.toString());
|
|
290
|
+
let i;
|
|
291
|
+
let n;
|
|
292
|
+
let allowed = false;
|
|
293
|
+
// Ensure that at least one item from the trusted resource URL list allows this url.
|
|
294
|
+
for (i = 0, n = trustedResourceUrlList.length; i < n; i++) {
|
|
295
|
+
if (matchUrl(trustedResourceUrlList[i], parsedUrl)) {
|
|
296
|
+
allowed = true;
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (allowed) {
|
|
301
|
+
// Ensure that no item from the banned resource URL list has blocked this url.
|
|
302
|
+
for (i = 0, n = bannedResourceUrlList.length; i < n; i++) {
|
|
303
|
+
if (matchUrl(bannedResourceUrlList[i], parsedUrl)) {
|
|
304
|
+
allowed = false;
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return allowed;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function generateHolderType(Base) {
|
|
313
|
+
const holderType = function TrustedValueHolderType(trustedValue) {
|
|
314
|
+
this.$$unwrapTrustedValue = function () {
|
|
315
|
+
return trustedValue;
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
if (Base) {
|
|
319
|
+
holderType.prototype = new Base();
|
|
320
|
+
}
|
|
321
|
+
holderType.prototype.valueOf = function sceValueOf() {
|
|
322
|
+
return this.$$unwrapTrustedValue();
|
|
323
|
+
};
|
|
324
|
+
holderType.prototype.toString = function sceToString() {
|
|
325
|
+
return this.$$unwrapTrustedValue().toString();
|
|
326
|
+
};
|
|
327
|
+
return holderType;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const trustedValueHolderBase = generateHolderType();
|
|
331
|
+
const byType = {};
|
|
332
|
+
|
|
333
|
+
byType[SCE_CONTEXTS.HTML] = generateHolderType(trustedValueHolderBase);
|
|
334
|
+
byType[SCE_CONTEXTS.CSS] = generateHolderType(trustedValueHolderBase);
|
|
335
|
+
byType[SCE_CONTEXTS.MEDIA_URL] = generateHolderType(
|
|
336
|
+
trustedValueHolderBase,
|
|
337
|
+
);
|
|
338
|
+
byType[SCE_CONTEXTS.URL] = generateHolderType(
|
|
339
|
+
byType[SCE_CONTEXTS.MEDIA_URL],
|
|
340
|
+
);
|
|
341
|
+
byType[SCE_CONTEXTS.JS] = generateHolderType(trustedValueHolderBase);
|
|
342
|
+
byType[SCE_CONTEXTS.RESOURCE_URL] = generateHolderType(
|
|
343
|
+
byType[SCE_CONTEXTS.URL],
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* @ngdoc method
|
|
348
|
+
* @name $sceDelegate#trustAs
|
|
349
|
+
*
|
|
350
|
+
* @description
|
|
351
|
+
* Returns a trusted representation of the parameter for the specified context. This trusted
|
|
352
|
+
* object will later on be used as-is, without any security check, by bindings or directives
|
|
353
|
+
* that require this security context.
|
|
354
|
+
* For instance, marking a string as trusted for the `$sce.HTML` context will entirely bypass
|
|
355
|
+
* the potential `$sanitize` call in corresponding `$sce.HTML` bindings or directives, such as
|
|
356
|
+
* `ng-bind-html`. Note that in most cases you won't need to call this function: if you have the
|
|
357
|
+
* sanitizer loaded, passing the value itself will render all the HTML that does not pose a
|
|
358
|
+
* security risk.
|
|
359
|
+
*
|
|
360
|
+
* See {@link ng.$sceDelegate#getTrusted getTrusted} for the function that will consume those
|
|
361
|
+
* trusted values, and {@link ng.$sce $sce} for general documentation about strict contextual
|
|
362
|
+
* escaping.
|
|
363
|
+
*
|
|
364
|
+
* @param {string} type The context in which this value is safe for use, e.g. `$sce.URL`,
|
|
365
|
+
* `$sce.RESOURCE_URL`, `$sce.HTML`, `$sce.JS` or `$sce.CSS`.
|
|
366
|
+
*
|
|
367
|
+
* @param {*} trustedValue The value that should be considered trusted.
|
|
368
|
+
* @return {*} A trusted representation of value, that can be used in the given context.
|
|
369
|
+
*/
|
|
370
|
+
function trustAs(type, trustedValue) {
|
|
371
|
+
const Constructor = Object.prototype.hasOwnProperty.call(byType, type)
|
|
372
|
+
? byType[type]
|
|
373
|
+
: null;
|
|
374
|
+
if (!Constructor) {
|
|
375
|
+
throw $sceMinErr(
|
|
376
|
+
"icontext",
|
|
377
|
+
"Attempted to trust a value in invalid context. Context: {0}; Value: {1}",
|
|
378
|
+
type,
|
|
379
|
+
trustedValue,
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
if (
|
|
383
|
+
trustedValue === null ||
|
|
384
|
+
isUndefined(trustedValue) ||
|
|
385
|
+
trustedValue === ""
|
|
386
|
+
) {
|
|
387
|
+
return trustedValue;
|
|
388
|
+
}
|
|
389
|
+
// All the current contexts in SCE_CONTEXTS happen to be strings. In order to avoid trusting
|
|
390
|
+
// mutable objects, we ensure here that the value passed in is actually a string.
|
|
391
|
+
if (typeof trustedValue !== "string") {
|
|
392
|
+
throw $sceMinErr(
|
|
393
|
+
"itype",
|
|
394
|
+
"Attempted to trust a non-string value in a content requiring a string: Context: {0}",
|
|
395
|
+
type,
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
return new Constructor(trustedValue);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* @ngdoc method
|
|
403
|
+
* @name $sceDelegate#valueOf
|
|
404
|
+
*
|
|
405
|
+
* @description
|
|
406
|
+
* If the passed parameter had been returned by a prior call to {@link ng.$sceDelegate#trustAs
|
|
407
|
+
* `$sceDelegate.trustAs`}, returns the value that had been passed to {@link
|
|
408
|
+
* ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}.
|
|
409
|
+
*
|
|
410
|
+
* If the passed parameter is not a value that had been returned by {@link
|
|
411
|
+
* ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}, it must be returned as-is.
|
|
412
|
+
*
|
|
413
|
+
* @param {*} maybeTrusted The result of a prior {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}
|
|
414
|
+
* call or anything else.
|
|
415
|
+
* @return {*} The `value` that was originally provided to {@link ng.$sceDelegate#trustAs
|
|
416
|
+
* `$sceDelegate.trustAs`} if `value` is the result of such a call. Otherwise, returns
|
|
417
|
+
* `value` unchanged.
|
|
418
|
+
*/
|
|
419
|
+
function valueOf(maybeTrusted) {
|
|
420
|
+
if (maybeTrusted instanceof trustedValueHolderBase) {
|
|
421
|
+
return maybeTrusted.$$unwrapTrustedValue();
|
|
422
|
+
}
|
|
423
|
+
return maybeTrusted;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* @ngdoc method
|
|
428
|
+
* @name $sceDelegate#getTrusted
|
|
429
|
+
*
|
|
430
|
+
* @description
|
|
431
|
+
* Given an object and a security context in which to assign it, returns a value that's safe to
|
|
432
|
+
* use in this context, which was represented by the parameter. To do so, this function either
|
|
433
|
+
* unwraps the safe type it has been given (for instance, a {@link ng.$sceDelegate#trustAs
|
|
434
|
+
* `$sceDelegate.trustAs`} result), or it might try to sanitize the value given, depending on
|
|
435
|
+
* the context and sanitizer availablility.
|
|
436
|
+
*
|
|
437
|
+
* The contexts that can be sanitized are $sce.MEDIA_URL, $sce.URL and $sce.HTML. The first two are available
|
|
438
|
+
* by default, and the third one relies on the `$sanitize` service (which may be loaded through
|
|
439
|
+
* the `ngSanitize` module). Furthermore, for $sce.RESOURCE_URL context, a plain string may be
|
|
440
|
+
* accepted if the resource url policy defined by {@link ng.$sceDelegateProvider#trustedResourceUrlList
|
|
441
|
+
* `$sceDelegateProvider.trustedResourceUrlList`} and {@link ng.$sceDelegateProvider#bannedResourceUrlList
|
|
442
|
+
* `$sceDelegateProvider.bannedResourceUrlList`} accepts that resource.
|
|
443
|
+
*
|
|
444
|
+
* This function will throw if the safe type isn't appropriate for this context, or if the
|
|
445
|
+
* value given cannot be accepted in the context (which might be caused by sanitization not
|
|
446
|
+
* being available, or the value not being recognized as safe).
|
|
447
|
+
*
|
|
448
|
+
* <div class="alert alert-danger">
|
|
449
|
+
* Disabling auto-escaping is extremely dangerous, it usually creates a Cross Site Scripting
|
|
450
|
+
* (XSS) vulnerability in your application.
|
|
451
|
+
* </div>
|
|
452
|
+
*
|
|
453
|
+
* @param {string} type The context in which this value is to be used (such as `$sce.HTML`).
|
|
454
|
+
* @param {*} maybeTrusted The result of a prior {@link ng.$sceDelegate#trustAs
|
|
455
|
+
* `$sceDelegate.trustAs`} call, or anything else (which will not be considered trusted.)
|
|
456
|
+
* @return {*} A version of the value that's safe to use in the given context, or throws an
|
|
457
|
+
* exception if this is impossible.
|
|
458
|
+
*/
|
|
459
|
+
function getTrusted(type, maybeTrusted) {
|
|
460
|
+
if (
|
|
461
|
+
maybeTrusted === null ||
|
|
462
|
+
isUndefined(maybeTrusted) ||
|
|
463
|
+
maybeTrusted === ""
|
|
464
|
+
) {
|
|
465
|
+
return maybeTrusted;
|
|
466
|
+
}
|
|
467
|
+
const constructor = Object.prototype.hasOwnProperty.call(byType, type)
|
|
468
|
+
? byType[type]
|
|
469
|
+
: null;
|
|
470
|
+
// If maybeTrusted is a trusted class instance or subclass instance, then unwrap and return
|
|
471
|
+
// as-is.
|
|
472
|
+
if (constructor && maybeTrusted instanceof constructor) {
|
|
473
|
+
return maybeTrusted.$$unwrapTrustedValue();
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// If maybeTrusted is a trusted class instance but not of the correct trusted type
|
|
477
|
+
// then unwrap it and allow it to pass through to the rest of the checks
|
|
478
|
+
if (isFunction(maybeTrusted.$$unwrapTrustedValue)) {
|
|
479
|
+
maybeTrusted = maybeTrusted.$$unwrapTrustedValue();
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// If we get here, then we will either sanitize the value or throw an exception.
|
|
483
|
+
if (type === SCE_CONTEXTS.MEDIA_URL || type === SCE_CONTEXTS.URL) {
|
|
484
|
+
// we attempt to sanitize non-resource URLs
|
|
485
|
+
return $$sanitizeUri(
|
|
486
|
+
maybeTrusted.toString(),
|
|
487
|
+
type === SCE_CONTEXTS.MEDIA_URL,
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
if (type === SCE_CONTEXTS.RESOURCE_URL) {
|
|
491
|
+
if (isResourceUrlAllowedByPolicy(maybeTrusted)) {
|
|
492
|
+
return maybeTrusted;
|
|
493
|
+
}
|
|
494
|
+
throw $sceMinErr(
|
|
495
|
+
"insecurl",
|
|
496
|
+
"Blocked loading resource from url not allowed by $sceDelegate policy. URL: {0}",
|
|
497
|
+
maybeTrusted.toString(),
|
|
498
|
+
);
|
|
499
|
+
} else if (type === SCE_CONTEXTS.HTML) {
|
|
500
|
+
// htmlSanitizer throws its own error when no sanitizer is available.
|
|
501
|
+
return htmlSanitizer(maybeTrusted);
|
|
502
|
+
}
|
|
503
|
+
// Default error when the $sce service has no way to make the input safe.
|
|
504
|
+
throw $sceMinErr(
|
|
505
|
+
"unsafe",
|
|
506
|
+
"Attempting to use an unsafe value in a safe context.",
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
return { trustAs, getTrusted, valueOf };
|
|
511
|
+
},
|
|
512
|
+
];
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* @ngdoc provider
|
|
517
|
+
* @name $sceProvider
|
|
518
|
+
*
|
|
519
|
+
*
|
|
520
|
+
* @description
|
|
521
|
+
*
|
|
522
|
+
* The $sceProvider provider allows developers to configure the {@link ng.$sce $sce} service.
|
|
523
|
+
* - enable/disable Strict Contextual Escaping (SCE) in a module
|
|
524
|
+
* - override the default implementation with a custom delegate
|
|
525
|
+
*
|
|
526
|
+
* Read more about {@link ng.$sce Strict Contextual Escaping (SCE)}.
|
|
527
|
+
*/
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* @ngdoc service
|
|
531
|
+
* @name $sce
|
|
532
|
+
* @kind function
|
|
533
|
+
*
|
|
534
|
+
* @description
|
|
535
|
+
*
|
|
536
|
+
* `$sce` is a service that provides Strict Contextual Escaping services to AngularJS.
|
|
537
|
+
*
|
|
538
|
+
* ## Strict Contextual Escaping
|
|
539
|
+
*
|
|
540
|
+
* Strict Contextual Escaping (SCE) is a mode in which AngularJS constrains bindings to only render
|
|
541
|
+
* trusted values. Its goal is to assist in writing code in a way that (a) is secure by default, and
|
|
542
|
+
* (b) makes auditing for security vulnerabilities such as XSS, clickjacking, etc. a lot easier.
|
|
543
|
+
*
|
|
544
|
+
* ### Overview
|
|
545
|
+
*
|
|
546
|
+
* To systematically block XSS security bugs, AngularJS treats all values as untrusted by default in
|
|
547
|
+
* HTML or sensitive URL bindings. When binding untrusted values, AngularJS will automatically
|
|
548
|
+
* run security checks on them (sanitizations, trusted URL resource, depending on context), or throw
|
|
549
|
+
* when it cannot guarantee the security of the result. That behavior depends strongly on contexts:
|
|
550
|
+
* HTML can be sanitized, but template URLs cannot, for instance.
|
|
551
|
+
*
|
|
552
|
+
* To illustrate this, consider the `ng-bind-html` directive. It renders its value directly as HTML:
|
|
553
|
+
* we call that the *context*. When given an untrusted input, AngularJS will attempt to sanitize it
|
|
554
|
+
* before rendering if a sanitizer is available, and throw otherwise. To bypass sanitization and
|
|
555
|
+
* render the input as-is, you will need to mark it as trusted for that context before attempting
|
|
556
|
+
* to bind it.
|
|
557
|
+
*
|
|
558
|
+
* As of version 1.2, AngularJS ships with SCE enabled by default.
|
|
559
|
+
*
|
|
560
|
+
* ### In practice
|
|
561
|
+
*
|
|
562
|
+
* Here's an example of a binding in a privileged context:
|
|
563
|
+
*
|
|
564
|
+
* ```
|
|
565
|
+
* <input ng-model="userHtml" aria-label="User input">
|
|
566
|
+
* <div ng-bind-html="userHtml"></div>
|
|
567
|
+
* ```
|
|
568
|
+
*
|
|
569
|
+
* Notice that `ng-bind-html` is bound to `userHtml` controlled by the user. With SCE
|
|
570
|
+
* disabled, this application allows the user to render arbitrary HTML into the DIV, which would
|
|
571
|
+
* be an XSS security bug. In a more realistic example, one may be rendering user comments, blog
|
|
572
|
+
* articles, etc. via bindings. (HTML is just one example of a context where rendering user
|
|
573
|
+
* controlled input creates security vulnerabilities.)
|
|
574
|
+
*
|
|
575
|
+
* For the case of HTML, you might use a library, either on the client side, or on the server side,
|
|
576
|
+
* to sanitize unsafe HTML before binding to the value and rendering it in the document.
|
|
577
|
+
*
|
|
578
|
+
* How would you ensure that every place that used these types of bindings was bound to a value that
|
|
579
|
+
* was sanitized by your library (or returned as safe for rendering by your server?) How can you
|
|
580
|
+
* ensure that you didn't accidentally delete the line that sanitized the value, or renamed some
|
|
581
|
+
* properties/fields and forgot to update the binding to the sanitized value?
|
|
582
|
+
*
|
|
583
|
+
* To be secure by default, AngularJS makes sure bindings go through that sanitization, or
|
|
584
|
+
* any similar validation process, unless there's a good reason to trust the given value in this
|
|
585
|
+
* context. That trust is formalized with a function call. This means that as a developer, you
|
|
586
|
+
* can assume all untrusted bindings are safe. Then, to audit your code for binding security issues,
|
|
587
|
+
* you just need to ensure the values you mark as trusted indeed are safe - because they were
|
|
588
|
+
* received from your server, sanitized by your library, etc. You can organize your codebase to
|
|
589
|
+
* help with this - perhaps allowing only the files in a specific directory to do this.
|
|
590
|
+
* Ensuring that the internal API exposed by that code doesn't markup arbitrary values as safe then
|
|
591
|
+
* becomes a more manageable task.
|
|
592
|
+
*
|
|
593
|
+
* In the case of AngularJS' SCE service, one uses {@link ng.$sce#trustAs $sce.trustAs}
|
|
594
|
+
* (and shorthand methods such as {@link ng.$sce#trustAsHtml $sce.trustAsHtml}, etc.) to
|
|
595
|
+
* build the trusted versions of your values.
|
|
596
|
+
*
|
|
597
|
+
* ### How does it work?
|
|
598
|
+
*
|
|
599
|
+
* In privileged contexts, directives and code will bind to the result of {@link ng.$sce#getTrusted
|
|
600
|
+
* $sce.getTrusted(context, value)} rather than to the value directly. Think of this function as
|
|
601
|
+
* a way to enforce the required security context in your data sink. Directives use {@link
|
|
602
|
+
* ng.$sce#parseAs $sce.parseAs} rather than `$parse` to watch attribute bindings, which performs
|
|
603
|
+
* the {@link ng.$sce#getTrusted $sce.getTrusted} behind the scenes on non-constant literals. Also,
|
|
604
|
+
* when binding without directives, AngularJS will understand the context of your bindings
|
|
605
|
+
* automatically.
|
|
606
|
+
*
|
|
607
|
+
* As an example, {@link ng.directive:ngBindHtml ngBindHtml} uses {@link
|
|
608
|
+
* ng.$sce#parseAsHtml $sce.parseAsHtml(binding expression)}. Here's the actual code (slightly
|
|
609
|
+
* simplified):
|
|
610
|
+
*
|
|
611
|
+
* ```
|
|
612
|
+
* let ngBindHtmlDirective = ['$sce', function($sce) {
|
|
613
|
+
* return function(scope, element, attr) {
|
|
614
|
+
* scope.$watch($sce.parseAsHtml(attr.ngBindHtml), function(value) {
|
|
615
|
+
* element.html(value || '');
|
|
616
|
+
* });
|
|
617
|
+
* };
|
|
618
|
+
* }];
|
|
619
|
+
* ```
|
|
620
|
+
*
|
|
621
|
+
* ### Impact on loading templates
|
|
622
|
+
*
|
|
623
|
+
* This applies both to the {@link ng.directive:ngInclude `ng-include`} directive as well as
|
|
624
|
+
* `templateUrl`'s specified by {@link guide/directive directives}.
|
|
625
|
+
*
|
|
626
|
+
* By default, AngularJS only loads templates from the same domain and protocol as the application
|
|
627
|
+
* document. This is done by calling {@link ng.$sce#getTrustedResourceUrl
|
|
628
|
+
* $sce.getTrustedResourceUrl} on the template URL. To load templates from other domains and/or
|
|
629
|
+
* protocols, you may either add them to the {@link ng.$sceDelegateProvider#trustedResourceUrlList
|
|
630
|
+
* trustedResourceUrlList} or {@link ng.$sce#trustAsResourceUrl wrap them} into trusted values.
|
|
631
|
+
*
|
|
632
|
+
* *Please note*:
|
|
633
|
+
* The browser's
|
|
634
|
+
* [Same Origin Policy](https://code.google.com/p/browsersec/wiki/Part2#Same-origin_policy_for_XMLHttpRequest)
|
|
635
|
+
* and [Cross-Origin Resource Sharing (CORS)](http://www.w3.org/TR/cors/)
|
|
636
|
+
* policy apply in addition to this and may further restrict whether the template is successfully
|
|
637
|
+
* loaded. This means that without the right CORS policy, loading templates from a different domain
|
|
638
|
+
* won't work on all browsers. Also, loading templates from `file://` URL does not work on some
|
|
639
|
+
* browsers.
|
|
640
|
+
*
|
|
641
|
+
* ### This feels like too much overhead
|
|
642
|
+
*
|
|
643
|
+
* It's important to remember that SCE only applies to interpolation expressions.
|
|
644
|
+
*
|
|
645
|
+
* If your expressions are constant literals, they're automatically trusted and you don't need to
|
|
646
|
+
* call `$sce.trustAs` on them (e.g.
|
|
647
|
+
* `<div ng-bind-html="'<b>implicitly trusted</b>'"></div>`) just works (remember to include the
|
|
648
|
+
* `ngSanitize` module). The `$sceDelegate` will also use the `$sanitize` service if it is available
|
|
649
|
+
* when binding untrusted values to `$sce.HTML` context.
|
|
650
|
+
* AngularJS provides an implementation in `angular-sanitize.js`, and if you
|
|
651
|
+
* wish to use it, you will also need to depend on the {@link ngSanitize `ngSanitize`} module in
|
|
652
|
+
* your application.
|
|
653
|
+
*
|
|
654
|
+
* The included {@link ng.$sceDelegate $sceDelegate} comes with sane defaults to allow you to load
|
|
655
|
+
* templates in `ng-include` from your application's domain without having to even know about SCE.
|
|
656
|
+
* It blocks loading templates from other domains or loading templates over http from an https
|
|
657
|
+
* served document. You can change these by setting your own custom {@link
|
|
658
|
+
* ng.$sceDelegateProvider#trustedResourceUrlList trusted resource URL list} and {@link
|
|
659
|
+
* ng.$sceDelegateProvider#bannedResourceUrlList banned resource URL list} for matching such URLs.
|
|
660
|
+
*
|
|
661
|
+
* This significantly reduces the overhead. It is far easier to pay the small overhead and have an
|
|
662
|
+
* application that's secure and can be audited to verify that with much more ease than bolting
|
|
663
|
+
* security onto an application later.
|
|
664
|
+
*
|
|
665
|
+
* <a name="contexts"></a>
|
|
666
|
+
* ### What trusted context types are supported?
|
|
667
|
+
*
|
|
668
|
+
* | Context | Notes |
|
|
669
|
+
* |---------------------|----------------|
|
|
670
|
+
* | `$sce.HTML` | For HTML that's safe to source into the application. The {@link ng.directive:ngBindHtml ngBindHtml} directive uses this context for bindings. If an unsafe value is encountered and the {@link ngSanitize $sanitize} module is present this will sanitize the value instead of throwing an error. |
|
|
671
|
+
* | `$sce.CSS` | For CSS that's safe to source into the application. Currently unused. Feel free to use it in your own directives. |
|
|
672
|
+
* | `$sce.MEDIA_URL` | For URLs that are safe to render as media. Is automatically converted from string by sanitizing when needed. |
|
|
673
|
+
* | `$sce.URL` | For URLs that are safe to follow as links. Is automatically converted from string by sanitizing when needed. Note that `$sce.URL` makes a stronger statement about the URL than `$sce.MEDIA_URL` does and therefore contexts requiring values trusted for `$sce.URL` can be used anywhere that values trusted for `$sce.MEDIA_URL` are required.|
|
|
674
|
+
* | `$sce.RESOURCE_URL` | For URLs that are not only safe to follow as links, but whose contents 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` or `$sce.MEDIA_URL` do and therefore contexts requiring values trusted for `$sce.RESOURCE_URL` can be used anywhere that values trusted for `$sce.URL` or `$sce.MEDIA_URL` are required. <br><br> The {@link $sceDelegateProvider#trustedResourceUrlList $sceDelegateProvider#trustedResourceUrlList()} and {@link $sceDelegateProvider#bannedResourceUrlList $sceDelegateProvider#bannedResourceUrlList()} can be used to restrict trusted origins for `RESOURCE_URL` |
|
|
675
|
+
* | `$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. |
|
|
676
|
+
*
|
|
677
|
+
*
|
|
678
|
+
* <div class="alert alert-warning">
|
|
679
|
+
* Be aware that, before AngularJS 1.7.0, `a[href]` and `img[src]` used to sanitize their
|
|
680
|
+
* interpolated values directly rather than rely upon {@link ng.$sce#getTrusted `$sce.getTrusted`}.
|
|
681
|
+
*
|
|
682
|
+
* **As of 1.7.0, this is no longer the case.**
|
|
683
|
+
*
|
|
684
|
+
* Now such interpolations are marked as requiring `$sce.URL` (for `a[href]`) or `$sce.MEDIA_URL`
|
|
685
|
+
* (for `img[src]`), so that the sanitization happens (via `$sce.getTrusted...`) when the `$interpolate`
|
|
686
|
+
* service evaluates the expressions.
|
|
687
|
+
* </div>
|
|
688
|
+
*
|
|
689
|
+
* There are no CSS or JS context bindings in AngularJS currently, so their corresponding `$sce.trustAs`
|
|
690
|
+
* functions aren't useful yet. This might evolve.
|
|
691
|
+
*
|
|
692
|
+
* ### Format of items in {@link ng.$sceDelegateProvider#trustedResourceUrlList trustedResourceUrlList}/{@link ng.$sceDelegateProvider#bannedResourceUrlList bannedResourceUrlList} <a name="resourceUrlPatternItem"></a>
|
|
693
|
+
*
|
|
694
|
+
* Each element in these arrays must be one of the following:
|
|
695
|
+
*
|
|
696
|
+
* - **'self'**
|
|
697
|
+
* - The special **string**, `'self'`, can be used to match against all URLs of the **same
|
|
698
|
+
* domain** as the application document using the **same protocol**.
|
|
699
|
+
* - **String** (except the special value `'self'`)
|
|
700
|
+
* - The string is matched against the full *normalized / absolute URL* of the resource
|
|
701
|
+
* being tested (substring matches are not good enough.)
|
|
702
|
+
* - There are exactly **two wildcard sequences** - `*` and `**`. All other characters
|
|
703
|
+
* match themselves.
|
|
704
|
+
* - `*`: matches zero or more occurrences of any character other than one of the following 6
|
|
705
|
+
* characters: '`:`', '`/`', '`.`', '`?`', '`&`' and '`;`'. It's a useful wildcard for use
|
|
706
|
+
* for matching resource URL lists.
|
|
707
|
+
* - `**`: matches zero or more occurrences of *any* character. As such, it's not
|
|
708
|
+
* appropriate for use in a scheme, domain, etc. as it would match too much. (e.g.
|
|
709
|
+
* http://**.example.com/ would match http://evil.com/?ignore=.example.com/ and that might
|
|
710
|
+
* not have been the intention.) Its usage at the very end of the path is ok. (e.g.
|
|
711
|
+
* http://foo.example.com/templates/**).
|
|
712
|
+
* - **RegExp** (*see caveat below*)
|
|
713
|
+
* - *Caveat*: While regular expressions are powerful and offer great flexibility, their syntax
|
|
714
|
+
* (and all the inevitable escaping) makes them *harder to maintain*. It's easy to
|
|
715
|
+
* accidentally introduce a bug when one updates a complex expression (imho, all regexes should
|
|
716
|
+
* have good test coverage). For instance, the use of `.` in the regex is correct only in a
|
|
717
|
+
* small number of cases. A `.` character in the regex used when matching the scheme or a
|
|
718
|
+
* subdomain could be matched against a `:` or literal `.` that was likely not intended. It
|
|
719
|
+
* is highly recommended to use the string patterns and only fall back to regular expressions
|
|
720
|
+
* as a last resort.
|
|
721
|
+
* - The regular expression must be an instance of RegExp (i.e. not a string.) It is
|
|
722
|
+
* matched against the **entire** *normalized / absolute URL* of the resource being tested
|
|
723
|
+
* (even when the RegExp did not have the `^` and `$` codes.) In addition, any flags
|
|
724
|
+
* present on the RegExp (such as multiline, global, ignoreCase) are ignored.
|
|
725
|
+
* - If you are generating your JavaScript from some other templating engine (not
|
|
726
|
+
* recommended, e.g. in issue [#4006](https://github.com/angular/angular.js/issues/4006)),
|
|
727
|
+
* remember to escape your regular expression (and be aware that you might need more than
|
|
728
|
+
* one level of escaping depending on your templating engine and the way you interpolated
|
|
729
|
+
* the value.) Do make use of your platform's escaping mechanism as it might be good
|
|
730
|
+
* enough before coding your own. E.g. Ruby has
|
|
731
|
+
* [Regexp.escape(str)](http://www.ruby-doc.org/core-2.0.0/Regexp.html#method-c-escape)
|
|
732
|
+
* and Python has [re.escape](http://docs.python.org/library/re.html#re.escape).
|
|
733
|
+
* Javascript lacks a similar built in function for escaping. Take a look at Google
|
|
734
|
+
* Closure library's [goog.string.regExpEscape(s)](
|
|
735
|
+
* http://docs.closure-library.googlecode.com/git/closure_goog_string_string.js.source.html#line962).
|
|
736
|
+
*
|
|
737
|
+
* Refer {@link ng.$sceDelegateProvider $sceDelegateProvider} for an example.
|
|
738
|
+
*
|
|
739
|
+
*
|
|
740
|
+
* ## Can I disable SCE completely?
|
|
741
|
+
*
|
|
742
|
+
* Yes, you can. However, this is strongly discouraged. SCE gives you a lot of security benefits
|
|
743
|
+
* for little coding overhead. It will be much harder to take an SCE disabled application and
|
|
744
|
+
* either secure it on your own or enable SCE at a later stage. It might make sense to disable SCE
|
|
745
|
+
* for cases where you have a lot of existing code that was written before SCE was introduced and
|
|
746
|
+
* you're migrating them a module at a time. Also do note that this is an app-wide setting, so if
|
|
747
|
+
* you are writing a library, you will cause security bugs applications using it.
|
|
748
|
+
*
|
|
749
|
+
* That said, here's how you can completely disable SCE:
|
|
750
|
+
*
|
|
751
|
+
* ```
|
|
752
|
+
* angular.module('myAppWithSceDisabledmyApp', []).config(function($sceProvider) {
|
|
753
|
+
* // Completely disable SCE. For demonstration purposes only!
|
|
754
|
+
* // Do not use in new projects or libraries.
|
|
755
|
+
* $sceProvider.enabled(false);
|
|
756
|
+
* });
|
|
757
|
+
* ```
|
|
758
|
+
*
|
|
759
|
+
*/
|
|
760
|
+
|
|
761
|
+
export function $SceProvider() {
|
|
762
|
+
let enabled = true;
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* @ngdoc method
|
|
766
|
+
* @name $sceProvider#enabled
|
|
767
|
+
* @kind function
|
|
768
|
+
*
|
|
769
|
+
* @param {boolean=} value If provided, then enables/disables SCE application-wide.
|
|
770
|
+
* @return {boolean} True if SCE is enabled, false otherwise.
|
|
771
|
+
*
|
|
772
|
+
* @description
|
|
773
|
+
* Enables/disables SCE and returns the current value.
|
|
774
|
+
*/
|
|
775
|
+
this.enabled = function (value) {
|
|
776
|
+
if (arguments.length) {
|
|
777
|
+
enabled = !!value;
|
|
778
|
+
}
|
|
779
|
+
return enabled;
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
/* Design notes on the default implementation for SCE.
|
|
783
|
+
*
|
|
784
|
+
* The API contract for the SCE delegate
|
|
785
|
+
* -------------------------------------
|
|
786
|
+
* The SCE delegate object must provide the following 3 methods:
|
|
787
|
+
*
|
|
788
|
+
* - trustAs(contextEnum, value)
|
|
789
|
+
* This method is used to tell the SCE service that the provided value is OK to use in the
|
|
790
|
+
* contexts specified by contextEnum. It must return an object that will be accepted by
|
|
791
|
+
* getTrusted() for a compatible contextEnum and return this value.
|
|
792
|
+
*
|
|
793
|
+
* - valueOf(value)
|
|
794
|
+
* For values that were not produced by trustAs(), return them as is. For values that were
|
|
795
|
+
* produced by trustAs(), return the corresponding input value to trustAs. Basically, if
|
|
796
|
+
* trustAs is wrapping the given values into some type, this operation unwraps it when given
|
|
797
|
+
* such a value.
|
|
798
|
+
*
|
|
799
|
+
* - getTrusted(contextEnum, value)
|
|
800
|
+
* This function should return the value that is safe to use in the context specified by
|
|
801
|
+
* contextEnum or throw and exception otherwise.
|
|
802
|
+
*
|
|
803
|
+
* NOTE: This contract deliberately does NOT state that values returned by trustAs() must be
|
|
804
|
+
* opaque or wrapped in some holder object. That happens to be an implementation detail. For
|
|
805
|
+
* instance, an implementation could maintain a registry of all trusted objects by context. In
|
|
806
|
+
* such a case, trustAs() would return the same object that was passed in. getTrusted() would
|
|
807
|
+
* return the same object passed in if it was found in the registry under a compatible context or
|
|
808
|
+
* throw an exception otherwise. An implementation might only wrap values some of the time based
|
|
809
|
+
* on some criteria. getTrusted() might return a value and not throw an exception for special
|
|
810
|
+
* constants or objects even if not wrapped. All such implementations fulfill this contract.
|
|
811
|
+
*
|
|
812
|
+
*
|
|
813
|
+
* A note on the inheritance model for SCE contexts
|
|
814
|
+
* ------------------------------------------------
|
|
815
|
+
* I've used inheritance and made RESOURCE_URL wrapped types a subtype of URL wrapped types. This
|
|
816
|
+
* is purely an implementation details.
|
|
817
|
+
*
|
|
818
|
+
* The contract is simply this:
|
|
819
|
+
*
|
|
820
|
+
* getTrusted($sce.RESOURCE_URL, value) succeeding implies that getTrusted($sce.URL, value)
|
|
821
|
+
* will also succeed.
|
|
822
|
+
*
|
|
823
|
+
* Inheritance happens to capture this in a natural way. In some future, we may not use
|
|
824
|
+
* inheritance anymore. That is OK because no code outside of sce.js and sceSpecs.js would need to
|
|
825
|
+
* be aware of this detail.
|
|
826
|
+
*/
|
|
827
|
+
|
|
828
|
+
this.$get = [
|
|
829
|
+
"$parse",
|
|
830
|
+
"$sceDelegate",
|
|
831
|
+
function ($parse, $sceDelegate) {
|
|
832
|
+
const sce = shallowCopy(SCE_CONTEXTS);
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* @ngdoc method
|
|
836
|
+
* @name $sce#isEnabled
|
|
837
|
+
* @kind function
|
|
838
|
+
*
|
|
839
|
+
* @return {Boolean} True if SCE is enabled, false otherwise. If you want to set the value, you
|
|
840
|
+
* have to do it at module config time on {@link ng.$sceProvider $sceProvider}.
|
|
841
|
+
*
|
|
842
|
+
* @description
|
|
843
|
+
* Returns a boolean indicating if SCE is enabled.
|
|
844
|
+
*/
|
|
845
|
+
sce.isEnabled = function () {
|
|
846
|
+
return enabled;
|
|
847
|
+
};
|
|
848
|
+
sce.trustAs = $sceDelegate.trustAs;
|
|
849
|
+
sce.getTrusted = $sceDelegate.getTrusted;
|
|
850
|
+
sce.valueOf = $sceDelegate.valueOf;
|
|
851
|
+
|
|
852
|
+
if (!enabled) {
|
|
853
|
+
sce.trustAs = sce.getTrusted = function (type, value) {
|
|
854
|
+
return value;
|
|
855
|
+
};
|
|
856
|
+
sce.valueOf = function ($) {
|
|
857
|
+
return $;
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* @ngdoc method
|
|
863
|
+
* @name $sce#parseAs
|
|
864
|
+
*
|
|
865
|
+
* @description
|
|
866
|
+
* Converts AngularJS {@link guide/expression expression} into a function. This is like {@link
|
|
867
|
+
* ng.$parse $parse} and is identical when the expression is a literal constant. Otherwise, it
|
|
868
|
+
* wraps the expression in a call to {@link ng.$sce#getTrusted $sce.getTrusted(*type*,
|
|
869
|
+
* *result*)}
|
|
870
|
+
*
|
|
871
|
+
* @param {string} type The SCE context in which this result will be used.
|
|
872
|
+
* @param {string} expr String expression to compile.
|
|
873
|
+
* @return {function(context, locals)} A function which represents the compiled expression:
|
|
874
|
+
*
|
|
875
|
+
* * `context` – `{object}` – an object against which any expressions embedded in the
|
|
876
|
+
* strings are evaluated against (typically a scope object).
|
|
877
|
+
* * `locals` – `{object=}` – local variables context object, useful for overriding values
|
|
878
|
+
* in `context`.
|
|
879
|
+
*/
|
|
880
|
+
sce.parseAs = function sceParseAs(type, expr) {
|
|
881
|
+
const parsed = $parse(expr);
|
|
882
|
+
if (parsed.literal && parsed.constant) {
|
|
883
|
+
return parsed;
|
|
884
|
+
}
|
|
885
|
+
return $parse(expr, (value) => sce.getTrusted(type, value));
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* @ngdoc method
|
|
890
|
+
* @name $sce#trustAs
|
|
891
|
+
*
|
|
892
|
+
* @description
|
|
893
|
+
* Delegates to {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}. As such, returns a
|
|
894
|
+
* wrapped object that represents your value, and the trust you have in its safety for the given
|
|
895
|
+
* context. AngularJS can then use that value as-is in bindings of the specified secure context.
|
|
896
|
+
* This is used in bindings for `ng-bind-html`, `ng-include`, and most `src` attribute
|
|
897
|
+
* interpolations. See {@link ng.$sce $sce} for strict contextual escaping.
|
|
898
|
+
*
|
|
899
|
+
* @param {string} type The context in which this value is safe for use, e.g. `$sce.URL`,
|
|
900
|
+
* `$sce.RESOURCE_URL`, `$sce.HTML`, `$sce.JS` or `$sce.CSS`.
|
|
901
|
+
*
|
|
902
|
+
* @param {*} value The value that that should be considered trusted.
|
|
903
|
+
* @return {*} A wrapped version of value that can be used as a trusted variant of your `value`
|
|
904
|
+
* in the context you specified.
|
|
905
|
+
*/
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* @ngdoc method
|
|
909
|
+
* @name $sce#trustAsHtml
|
|
910
|
+
*
|
|
911
|
+
* @description
|
|
912
|
+
* Shorthand method. `$sce.trustAsHtml(value)` →
|
|
913
|
+
* {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.HTML, value)`}
|
|
914
|
+
*
|
|
915
|
+
* @param {*} value The value to mark as trusted for `$sce.HTML` context.
|
|
916
|
+
* @return {*} A wrapped version of value that can be used as a trusted variant of your `value`
|
|
917
|
+
* in `$sce.HTML` context (like `ng-bind-html`).
|
|
918
|
+
*/
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* @ngdoc method
|
|
922
|
+
* @name $sce#trustAsCss
|
|
923
|
+
*
|
|
924
|
+
* @description
|
|
925
|
+
* Shorthand method. `$sce.trustAsCss(value)` →
|
|
926
|
+
* {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.CSS, value)`}
|
|
927
|
+
*
|
|
928
|
+
* @param {*} value The value to mark as trusted for `$sce.CSS` context.
|
|
929
|
+
* @return {*} A wrapped version of value that can be used as a trusted variant
|
|
930
|
+
* of your `value` in `$sce.CSS` context. This context is currently unused, so there are
|
|
931
|
+
* almost no reasons to use this function so far.
|
|
932
|
+
*/
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* @ngdoc method
|
|
936
|
+
* @name $sce#trustAsUrl
|
|
937
|
+
*
|
|
938
|
+
* @description
|
|
939
|
+
* Shorthand method. `$sce.trustAsUrl(value)` →
|
|
940
|
+
* {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.URL, value)`}
|
|
941
|
+
*
|
|
942
|
+
* @param {*} value The value to mark as trusted for `$sce.URL` context.
|
|
943
|
+
* @return {*} A wrapped version of value that can be used as a trusted variant of your `value`
|
|
944
|
+
* in `$sce.URL` context. That context is currently unused, so there are almost no reasons
|
|
945
|
+
* to use this function so far.
|
|
946
|
+
*/
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* @ngdoc method
|
|
950
|
+
* @name $sce#trustAsResourceUrl
|
|
951
|
+
*
|
|
952
|
+
* @description
|
|
953
|
+
* Shorthand method. `$sce.trustAsResourceUrl(value)` →
|
|
954
|
+
* {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.RESOURCE_URL, value)`}
|
|
955
|
+
*
|
|
956
|
+
* @param {*} value The value to mark as trusted for `$sce.RESOURCE_URL` context.
|
|
957
|
+
* @return {*} A wrapped version of value that can be used as a trusted variant of your `value`
|
|
958
|
+
* in `$sce.RESOURCE_URL` context (template URLs in `ng-include`, most `src` attribute
|
|
959
|
+
* bindings, ...)
|
|
960
|
+
*/
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* @ngdoc method
|
|
964
|
+
* @name $sce#trustAsJs
|
|
965
|
+
*
|
|
966
|
+
* @description
|
|
967
|
+
* Shorthand method. `$sce.trustAsJs(value)` →
|
|
968
|
+
* {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.JS, value)`}
|
|
969
|
+
*
|
|
970
|
+
* @param {*} value The value to mark as trusted for `$sce.JS` context.
|
|
971
|
+
* @return {*} A wrapped version of value that can be used as a trusted variant of your `value`
|
|
972
|
+
* in `$sce.JS` context. That context is currently unused, so there are almost no reasons to
|
|
973
|
+
* use this function so far.
|
|
974
|
+
*/
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* @ngdoc method
|
|
978
|
+
* @name $sce#getTrusted
|
|
979
|
+
*
|
|
980
|
+
* @description
|
|
981
|
+
* Delegates to {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted`}. As such,
|
|
982
|
+
* takes any input, and either returns a value that's safe to use in the specified context,
|
|
983
|
+
* or throws an exception. This function is aware of trusted values created by the `trustAs`
|
|
984
|
+
* function and its shorthands, and when contexts are appropriate, returns the unwrapped value
|
|
985
|
+
* as-is. Finally, this function can also throw when there is no way to turn `maybeTrusted` in a
|
|
986
|
+
* safe value (e.g., no sanitization is available or possible.)
|
|
987
|
+
*
|
|
988
|
+
* @param {string} type The context in which this value is to be used.
|
|
989
|
+
* @param {*} maybeTrusted The result of a prior {@link ng.$sce#trustAs
|
|
990
|
+
* `$sce.trustAs`} call, or anything else (which will not be considered trusted.)
|
|
991
|
+
* @return {*} A version of the value that's safe to use in the given context, or throws an
|
|
992
|
+
* exception if this is impossible.
|
|
993
|
+
*/
|
|
994
|
+
|
|
995
|
+
/**
|
|
996
|
+
* @ngdoc method
|
|
997
|
+
* @name $sce#getTrustedHtml
|
|
998
|
+
*
|
|
999
|
+
* @description
|
|
1000
|
+
* Shorthand method. `$sce.getTrustedHtml(value)` →
|
|
1001
|
+
* {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.HTML, value)`}
|
|
1002
|
+
*
|
|
1003
|
+
* @param {*} value The value to pass to `$sce.getTrusted`.
|
|
1004
|
+
* @return {*} The return value of `$sce.getTrusted($sce.HTML, value)`
|
|
1005
|
+
*/
|
|
1006
|
+
|
|
1007
|
+
/**
|
|
1008
|
+
* @ngdoc method
|
|
1009
|
+
* @name $sce#getTrustedCss
|
|
1010
|
+
*
|
|
1011
|
+
* @description
|
|
1012
|
+
* Shorthand method. `$sce.getTrustedCss(value)` →
|
|
1013
|
+
* {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.CSS, value)`}
|
|
1014
|
+
*
|
|
1015
|
+
* @param {*} value The value to pass to `$sce.getTrusted`.
|
|
1016
|
+
* @return {*} The return value of `$sce.getTrusted($sce.CSS, value)`
|
|
1017
|
+
*/
|
|
1018
|
+
|
|
1019
|
+
/**
|
|
1020
|
+
* @ngdoc method
|
|
1021
|
+
* @name $sce#getTrustedUrl
|
|
1022
|
+
*
|
|
1023
|
+
* @description
|
|
1024
|
+
* Shorthand method. `$sce.getTrustedUrl(value)` →
|
|
1025
|
+
* {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.URL, value)`}
|
|
1026
|
+
*
|
|
1027
|
+
* @param {*} value The value to pass to `$sce.getTrusted`.
|
|
1028
|
+
* @return {*} The return value of `$sce.getTrusted($sce.URL, value)`
|
|
1029
|
+
*/
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* @ngdoc method
|
|
1033
|
+
* @name $sce#getTrustedResourceUrl
|
|
1034
|
+
*
|
|
1035
|
+
* @description
|
|
1036
|
+
* Shorthand method. `$sce.getTrustedResourceUrl(value)` →
|
|
1037
|
+
* {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.RESOURCE_URL, value)`}
|
|
1038
|
+
*
|
|
1039
|
+
* @param {*} value The value to pass to `$sceDelegate.getTrusted`.
|
|
1040
|
+
* @return {*} The return value of `$sce.getTrusted($sce.RESOURCE_URL, value)`
|
|
1041
|
+
*/
|
|
1042
|
+
|
|
1043
|
+
/**
|
|
1044
|
+
* @ngdoc method
|
|
1045
|
+
* @name $sce#getTrustedJs
|
|
1046
|
+
*
|
|
1047
|
+
* @description
|
|
1048
|
+
* Shorthand method. `$sce.getTrustedJs(value)` →
|
|
1049
|
+
* {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.JS, value)`}
|
|
1050
|
+
*
|
|
1051
|
+
* @param {*} value The value to pass to `$sce.getTrusted`.
|
|
1052
|
+
* @return {*} The return value of `$sce.getTrusted($sce.JS, value)`
|
|
1053
|
+
*/
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* @ngdoc method
|
|
1057
|
+
* @name $sce#parseAsHtml
|
|
1058
|
+
*
|
|
1059
|
+
* @description
|
|
1060
|
+
* Shorthand method. `$sce.parseAsHtml(expression string)` →
|
|
1061
|
+
* {@link ng.$sce#parseAs `$sce.parseAs($sce.HTML, value)`}
|
|
1062
|
+
*
|
|
1063
|
+
* @param {string} expression String expression to compile.
|
|
1064
|
+
* @return {function(context, locals)} A function which represents the compiled expression:
|
|
1065
|
+
*
|
|
1066
|
+
* * `context` – `{object}` – an object against which any expressions embedded in the
|
|
1067
|
+
* strings are evaluated against (typically a scope object).
|
|
1068
|
+
* * `locals` – `{object=}` – local variables context object, useful for overriding values
|
|
1069
|
+
* in `context`.
|
|
1070
|
+
*/
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* @ngdoc method
|
|
1074
|
+
* @name $sce#parseAsCss
|
|
1075
|
+
*
|
|
1076
|
+
* @description
|
|
1077
|
+
* Shorthand method. `$sce.parseAsCss(value)` →
|
|
1078
|
+
* {@link ng.$sce#parseAs `$sce.parseAs($sce.CSS, value)`}
|
|
1079
|
+
*
|
|
1080
|
+
* @param {string} expression String expression to compile.
|
|
1081
|
+
* @return {function(context, locals)} A function which represents the compiled expression:
|
|
1082
|
+
*
|
|
1083
|
+
* * `context` – `{object}` – an object against which any expressions embedded in the
|
|
1084
|
+
* strings are evaluated against (typically a scope object).
|
|
1085
|
+
* * `locals` – `{object=}` – local variables context object, useful for overriding values
|
|
1086
|
+
* in `context`.
|
|
1087
|
+
*/
|
|
1088
|
+
|
|
1089
|
+
/**
|
|
1090
|
+
* @ngdoc method
|
|
1091
|
+
* @name $sce#parseAsUrl
|
|
1092
|
+
*
|
|
1093
|
+
* @description
|
|
1094
|
+
* Shorthand method. `$sce.parseAsUrl(value)` →
|
|
1095
|
+
* {@link ng.$sce#parseAs `$sce.parseAs($sce.URL, value)`}
|
|
1096
|
+
*
|
|
1097
|
+
* @param {string} expression String expression to compile.
|
|
1098
|
+
* @return {function(context, locals)} A function which represents the compiled expression:
|
|
1099
|
+
*
|
|
1100
|
+
* * `context` – `{object}` – an object against which any expressions embedded in the
|
|
1101
|
+
* strings are evaluated against (typically a scope object).
|
|
1102
|
+
* * `locals` – `{object=}` – local variables context object, useful for overriding values
|
|
1103
|
+
* in `context`.
|
|
1104
|
+
*/
|
|
1105
|
+
|
|
1106
|
+
/**
|
|
1107
|
+
* @ngdoc method
|
|
1108
|
+
* @name $sce#parseAsResourceUrl
|
|
1109
|
+
*
|
|
1110
|
+
* @description
|
|
1111
|
+
* Shorthand method. `$sce.parseAsResourceUrl(value)` →
|
|
1112
|
+
* {@link ng.$sce#parseAs `$sce.parseAs($sce.RESOURCE_URL, value)`}
|
|
1113
|
+
*
|
|
1114
|
+
* @param {string} expression String expression to compile.
|
|
1115
|
+
* @return {function(context, locals)} A function which represents the compiled expression:
|
|
1116
|
+
*
|
|
1117
|
+
* * `context` – `{object}` – an object against which any expressions embedded in the
|
|
1118
|
+
* strings are evaluated against (typically a scope object).
|
|
1119
|
+
* * `locals` – `{object=}` – local variables context object, useful for overriding values
|
|
1120
|
+
* in `context`.
|
|
1121
|
+
*/
|
|
1122
|
+
|
|
1123
|
+
/**
|
|
1124
|
+
* @ngdoc method
|
|
1125
|
+
* @name $sce#parseAsJs
|
|
1126
|
+
*
|
|
1127
|
+
* @description
|
|
1128
|
+
* Shorthand method. `$sce.parseAsJs(value)` →
|
|
1129
|
+
* {@link ng.$sce#parseAs `$sce.parseAs($sce.JS, value)`}
|
|
1130
|
+
*
|
|
1131
|
+
* @param {string} expression String expression to compile.
|
|
1132
|
+
* @return {function(context, locals)} A function which represents the compiled expression:
|
|
1133
|
+
*
|
|
1134
|
+
* * `context` – `{object}` – an object against which any expressions embedded in the
|
|
1135
|
+
* strings are evaluated against (typically a scope object).
|
|
1136
|
+
* * `locals` – `{object=}` – local variables context object, useful for overriding values
|
|
1137
|
+
* in `context`.
|
|
1138
|
+
*/
|
|
1139
|
+
|
|
1140
|
+
// Shorthand delegations.
|
|
1141
|
+
const parse = sce.parseAs;
|
|
1142
|
+
const { getTrusted } = sce;
|
|
1143
|
+
const { trustAs } = sce;
|
|
1144
|
+
|
|
1145
|
+
forEach(SCE_CONTEXTS, (enumValue, name) => {
|
|
1146
|
+
const lName = lowercase(name);
|
|
1147
|
+
sce[snakeToCamel(`parse_as_${lName}`)] = function (expr) {
|
|
1148
|
+
return parse(enumValue, expr);
|
|
1149
|
+
};
|
|
1150
|
+
sce[snakeToCamel(`get_trusted_${lName}`)] = function (value) {
|
|
1151
|
+
return getTrusted(enumValue, value);
|
|
1152
|
+
};
|
|
1153
|
+
sce[snakeToCamel(`trust_as_${lName}`)] = function (value) {
|
|
1154
|
+
return trustAs(enumValue, value);
|
|
1155
|
+
};
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
return sce;
|
|
1159
|
+
},
|
|
1160
|
+
];
|
|
1161
|
+
}
|