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

Commit 0397e29

Browse files
topherfangioThomasBurleson
authored andcommitted
fix(all): Use $templateRequest instead of $http for security.
For security purposes, we have switched from using `$http` for our template and icon requests to using `$templateRequest` since it provides some automatic caching, and more importantly, security checks about the URL/data. See https://docs.angularjs.org/api/ng/service/$templateRequest for more information. Fixes #8413. Closes #8423
1 parent b528ca2 commit 0397e29

File tree

13 files changed

+52
-50
lines changed

13 files changed

+52
-50
lines changed

docs/app/js/app.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,8 @@ function($scope, doc, component, $rootScope) {
722722
'$scope',
723723
'component',
724724
'demos',
725-
'$http',
726-
'$templateCache',
727-
function($rootScope, $scope, component, demos, $http, $templateCache) {
725+
'$templateRequest',
726+
function($rootScope, $scope, component, demos, $templateRequest) {
728727
$rootScope.currentComponent = component;
729728
$rootScope.currentDoc = null;
730729

@@ -737,9 +736,9 @@ function($rootScope, $scope, component, demos, $http, $templateCache) {
737736
.concat(demo.css || [])
738737
.concat(demo.html || []);
739738
files.forEach(function(file) {
740-
file.httpPromise =$http.get(file.outputPath, {cache: $templateCache})
739+
file.httpPromise = $templateRequest(file.outputPath)
741740
.then(function(response) {
742-
file.contents = response.data
741+
file.contents = response
743742
.replace('<head/>', '');
744743
return file.contents;
745744
});

docs/app/js/demoInclude.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
DocsApp.directive('demoInclude', [
22
'$q',
3-
'$http',
43
'$compile',
5-
'$templateCache',
64
'$timeout',
7-
function($q, $http, $compile, $templateCache, $timeout) {
5+
function($q, $compile, $timeout) {
86
return {
97
restrict: 'E',
108
link: postLink

docs/config/template/index.template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ <h2 class="md-toolbar-item md-breadcrumb md-headline">
159159
<div layout="row" flex="noshrink" layout-align="center center">
160160
<div id="license-footer" flex>
161161
Powered by Google &copy;2014&#8211;{{thisYear}}.
162-
Code licensed under the <a href="./license" class="md-accent">MIT License</a>.
162+
Code licensed under the <a ng-href="./license" class="md-accent">MIT License</a>.
163163
Documentation licensed under
164164
<a href="http://creativecommons.org/licenses/by/4.0/" target="_blank" class="md-default-theme md-accent">CC BY 4.0</a>.
165165
</div>

src/components/bottomSheet/demoBasicUsage/script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ angular.module('bottomSheetDemo1', ['ngMaterial'])
7171
$mdBottomSheet.hide(clickedItem);
7272
};
7373
})
74-
.run(function($http, $templateCache) {
74+
.run(function($templateResult) {
7575

7676
var urls = [
7777
'img/icons/share-arrow.svg',
@@ -87,7 +87,7 @@ angular.module('bottomSheetDemo1', ['ngMaterial'])
8787
];
8888

8989
angular.forEach(urls, function(url) {
90-
$http.get(url, {cache: $templateCache});
90+
$templateResult(url);
9191
});
9292

9393
});

src/components/icon/demoUsingTemplateCache/index.html renamed to src/components/icon/demoUsingTemplateRequest/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div ng-controller="DemoCtrl" layout="column" layout-margin ng-cloak>
22

33
<p>
4-
Pre-fetch with $http & cache SVG icons using $templateCache.<br/>
4+
Pre-fetch and cache SVG icons using $templateRequest.<br/>
55
<span class="note"> NOTE: Show the Source views for details...</span>
66
</p>
77

src/components/icon/demoUsingTemplateCache/script.js renamed to src/components/icon/demoUsingTemplateRequest/script.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ angular.module('appUsingTemplateCache', ['ngMaterial'])
44
.config(function($mdIconProvider) {
55

66
// Register icon IDs with sources. Future $mdIcon( <id> ) lookups
7-
// will load by url and retrieve the data via the $http and $templateCache
7+
// will load by url and retrieve the data via the $templateRequest
88

99
$mdIconProvider
1010
.iconSet('core', 'img/icons/sets/core-icons.svg',24)
1111
.icon('social:cake', 'img/icons/cake.svg',24);
1212

1313
})
14-
.run(function($http, $templateCache) {
14+
.run(function($templateRequest) {
1515

1616
var urls = [
1717
'img/icons/sets/core-icons.svg',
@@ -20,10 +20,10 @@ angular.module('appUsingTemplateCache', ['ngMaterial'])
2020
];
2121

2222
// Pre-fetch icons sources by URL and cache in the $templateCache...
23-
// subsequent $http calls will look there first.
23+
// subsequent $templateRequest calls will look there first.
2424

2525
angular.forEach(urls, function(url) {
26-
$http.get(url, {cache: $templateCache});
26+
$templateRequest(url);
2727
});
2828

2929
})

0 commit comments

Comments
 (0)