|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const { prepareTestServerForIast } = require('../utils') |
| 4 | +const { storage } = require('../../../../../datadog-core') |
| 5 | +const iastContextFunctions = require('../../../../src/appsec/iast/iast-context') |
| 6 | +const { newTaintedString } = require('../../../../src/appsec/iast/taint-tracking/operations') |
| 7 | + |
| 8 | +describe('template-injection-analyzer with handlebars', () => { |
| 9 | + withVersions('handlebars', 'handlebars', version => { |
| 10 | + let source |
| 11 | + before(() => { |
| 12 | + source = '<p>{{name}}</p>' |
| 13 | + }) |
| 14 | + |
| 15 | + describe('compile', () => { |
| 16 | + prepareTestServerForIast('template injection analyzer', |
| 17 | + (testThatRequestHasVulnerability, testThatRequestHasNoVulnerability) => { |
| 18 | + let lib |
| 19 | + beforeEach(() => { |
| 20 | + lib = require(`../../../../../../versions/handlebars@${version}`).get() |
| 21 | + }) |
| 22 | + |
| 23 | + testThatRequestHasVulnerability(() => { |
| 24 | + const store = storage.getStore() |
| 25 | + const iastContext = iastContextFunctions.getIastContext(store) |
| 26 | + const template = newTaintedString(iastContext, source, 'param', 'Request') |
| 27 | + lib.compile(template) |
| 28 | + }, 'TEMPLATE_INJECTION') |
| 29 | + |
| 30 | + testThatRequestHasNoVulnerability(() => { |
| 31 | + lib.compile(source) |
| 32 | + }, 'TEMPLATE_INJECTION') |
| 33 | + }) |
| 34 | + }) |
| 35 | + |
| 36 | + describe('precompile', () => { |
| 37 | + prepareTestServerForIast('template injection analyzer', |
| 38 | + (testThatRequestHasVulnerability, testThatRequestHasNoVulnerability) => { |
| 39 | + let lib |
| 40 | + beforeEach(() => { |
| 41 | + lib = require(`../../../../../../versions/handlebars@${version}`).get() |
| 42 | + }) |
| 43 | + |
| 44 | + testThatRequestHasVulnerability(() => { |
| 45 | + const store = storage.getStore() |
| 46 | + const iastContext = iastContextFunctions.getIastContext(store) |
| 47 | + const template = newTaintedString(iastContext, source, 'param', 'Request') |
| 48 | + lib.precompile(template) |
| 49 | + }, 'TEMPLATE_INJECTION') |
| 50 | + |
| 51 | + testThatRequestHasNoVulnerability(() => { |
| 52 | + lib.precompile(source) |
| 53 | + }, 'TEMPLATE_INJECTION') |
| 54 | + }) |
| 55 | + }) |
| 56 | + |
| 57 | + describe('registerPartial', () => { |
| 58 | + prepareTestServerForIast('template injection analyzer', |
| 59 | + (testThatRequestHasVulnerability, testThatRequestHasNoVulnerability) => { |
| 60 | + let lib |
| 61 | + beforeEach(() => { |
| 62 | + lib = require(`../../../../../../versions/handlebars@${version}`).get() |
| 63 | + }) |
| 64 | + |
| 65 | + testThatRequestHasVulnerability(() => { |
| 66 | + const store = storage.getStore() |
| 67 | + const iastContext = iastContextFunctions.getIastContext(store) |
| 68 | + const partial = newTaintedString(iastContext, source, 'param', 'Request') |
| 69 | + |
| 70 | + lib.registerPartial('vulnerablePartial', partial) |
| 71 | + }, 'TEMPLATE_INJECTION') |
| 72 | + |
| 73 | + testThatRequestHasNoVulnerability(() => { |
| 74 | + lib.registerPartial('vulnerablePartial', source) |
| 75 | + }, 'TEMPLATE_INJECTION') |
| 76 | + }) |
| 77 | + }) |
| 78 | + }) |
| 79 | +}) |
0 commit comments