-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from microsoft/dev/vflouirac/update-no-angular…
…js-sanitization-whitelist Dev/vflouirac/update no angularjs sanitization whitelist
- Loading branch information
Showing
3 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** | ||
* @fileoverview Rule to disallow modifying sanitization allowed url list in AngularJS. Update fron the deprecate SanitizationWhitelist | ||
* @author Vivien Flouirac | ||
*/ | ||
|
||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
module.exports = { | ||
meta: { | ||
type: "suggestion", | ||
fixable: "code", | ||
schema: [], | ||
docs: { | ||
category: "Security", | ||
description: "Calls to [`$compileProvider.aHrefSanitizationTrustedUrlList`](https://docs.angularjs.org/api/ng/provider/$compileProvider#aHrefSanitizationTrustedUrlList) configure allowed Url list in AngularJS sanitizer and need to be reviewed.", | ||
url: "https://github.com/microsoft/eslint-plugin-sdl/blob/master/docs/rules/no-angular-sanitization-trusted-urls.md" | ||
}, | ||
messages: { | ||
noSanitizationTrustedUrls: "Do not modify the trusted Urls list in AngularJS" | ||
} | ||
}, | ||
create: function(context) { | ||
return { | ||
"CallExpression[arguments!=''][callee.object.name='$compileProvider'][callee.property.name=/(aHref|imgSrc)SanitizationTrustedUrlList/]"(node) { | ||
context.report( | ||
{ | ||
node: node, | ||
messageId: "noSanitizationTrustedUrls" | ||
}); | ||
} | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
const path = require("path"); | ||
const ruleId = path.parse(__filename).name; | ||
const rule = require(path.join('../../../lib/rules/', ruleId)); | ||
const RuleTester = require("eslint").RuleTester; | ||
var ruleTester = new RuleTester(); | ||
|
||
ruleTester.run(ruleId, rule, { | ||
valid: [ | ||
"aHrefSanitizationTrustedUrlList ('.*')", | ||
"x.aHrefSanitizationTrustedUrlList ('.*')", | ||
"$compileProvider.aHrefSanitizationTrustedUrlList ()", | ||
"$compileProvider.AHrefSanitizationTrustedUrlList ('.*')" | ||
], | ||
invalid: [ | ||
{ | ||
code: "$compileProvider.aHrefSanitizationTrustedUrlList ('.*');", | ||
errors: [ | ||
{ | ||
messageId: "noSanitizationTrustedUrls", | ||
line: 1, | ||
endLine: 1, | ||
column: 1, | ||
endColumn: 56 | ||
} | ||
] | ||
}, | ||
{ | ||
code: "$compileProvider.imgSrcSanitizationTrustedUrlList('.*');", | ||
errors: [ | ||
{ | ||
messageId: "noSanitizationTrustedUrls", | ||
line: 1, | ||
endLine: 1, | ||
column: 1, | ||
endColumn: 56 | ||
} | ||
] | ||
} | ||
] | ||
}); |