-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent possibility of execution of the code injected via protot…
…ype pollution when undefined is passed to compiled template function, closes #291
- Loading branch information
1 parent
299b4da
commit 2cf2226
Showing
3 changed files
with
33 additions
and
1 deletion.
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
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,31 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
var doT = require('..'); | ||
|
||
|
||
describe('doT.process', function() { | ||
describe('polluting object prototype should not affect template compilation', function() { | ||
it('should ignore varname on object prototype', function() { | ||
var currentLog = console.log; | ||
console.log = log; | ||
var logged; | ||
|
||
Object.prototype.templateSettings = {varname: 'it=(console.log("executed"),{})'}; | ||
|
||
try { | ||
const templates = doT.process({path: './test'}); | ||
assert.notEqual(logged, 'executed'); | ||
// injected code can only be executed if undefined is passed to template function | ||
templates.test(); | ||
assert.notEqual(logged, 'executed'); | ||
} finally { | ||
console.log = currentLog; | ||
} | ||
|
||
function log(str) { | ||
logged = str; | ||
} | ||
}) | ||
}); | ||
}); |
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 @@ | ||
{{=it && it.test}} |