Skip to content

Commit

Permalink
trying fix
Browse files Browse the repository at this point in the history
  • Loading branch information
uurien committed Jan 14, 2025
1 parent 638a68a commit 03b53f1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fs from 'fs'
import { csiMethods } from './csi-methods.js'

Check failure on line 6 in packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs

View workflow job for this annotation

GitHub Actions / lint

'csiMethods' is defined but never used
import { getName } from '../telemetry/verbosity.js'
import { isNotLibraryFile, isPrivateModule } from './filter.js'

console.log('rewriter-esm')

Check failure on line 9 in packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
const currentUrl = new URL(import.meta.url)
const ddTraceDir = path.join(currentUrl.pathname, '..', '..', '..', '..', '..', '..')

Expand All @@ -24,6 +24,7 @@ function log (...msgs) {
}

export async function initialize (data) {
console.log('rewriter-esm - initialize')

Check failure on line 27 in packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
if (rewriter) return Promise.reject(new Error('ALREADY INITIALIZED'))

const { csiMethods, telemetryVerbosity, chainSourceMap } = data
Expand All @@ -48,6 +49,7 @@ export async function load (url, context, nextLoad) {
if (url.includes(ddTraceDir) || url.includes('iitm=true')) return result

try {
console.log('rewriter-esm - load - ' + url)

Check failure on line 52 in packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
if (isPrivateModule(url) && isNotLibraryFile(url)) {
const rewritten = rewriter.rewrite(result.source.toString(), url)

Expand All @@ -72,6 +74,9 @@ export async function load (url, context, nextLoad) {
data
})
}

if (url.includes('index.mjs')) {
console.log('result.source - index.mjs')

Check failure on line 78 in packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log(result.source)

Check failure on line 79 in packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}
return result
}
45 changes: 32 additions & 13 deletions packages/dd-trace/test/appsec/iast/index.esm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('ESM', () => {
after(async function () {
await sandbox.remove()
})
const nodeOptionsList = ['--import dd-trace/initialize.mjs', '--require dd-trace/init.js --loader dd-trace/initialize.mjs']
const nodeOptionsList = ['--import dd-trace/initialize.mjs', '--require dd-trace/init.js --loader dd-trace/loader-hook.mjs']

nodeOptionsList.forEach(nodeOptions => {
describe(`with NODE_OPTIONS=${nodeOptions}`, () => {
Expand All @@ -49,19 +49,36 @@ describe('ESM', () => {
await agent.stop()
})

function verifySpan (payload, verify) {
let err
for (let i = 0; i < payload.length; i++) {
const trace = payload[i]
for (let j = 0; j < trace.length; j++) {
try {
verify(trace[j])
return
} catch (e) {
err = err || e
}
}
}
throw err
}

it('test endpoint have COMMAND_INJECTION vulnerability', async function () {
this.timeout(30000)
console.log('00 A')
await axios.get('/cmdi-vulnerable?args=-la')
console.log('10 A')

await agent.assertMessageReceived(({ payload }) => {
console.log('20 A', payload)
assert.property(payload[0][0].meta, '_dd.iast.json')
console.log('30 A', payload)
assert.include(payload[0][0].meta['_dd.iast.json'], '"COMMAND_INJECTION"')
console.log('40 A', payload)
})
verifySpan(payload, span => {
assert.property(span.meta, '_dd.iast.json')
console.log('30 A', JSON.stringify(span.meta))
assert.include(span.meta['_dd.iast.json'], '"COMMAND_INJECTION"')
console.log('40 A')
})
}, null, 1, true)
})

it('test endpoint have COMMAND_INJECTION vulnerability in imported file', async () => {
Expand All @@ -70,12 +87,14 @@ describe('ESM', () => {
console.log('10 B')

await agent.assertMessageReceived(({ payload }) => {
console.log('20 B')
assert.property(payload[0][0].meta, '_dd.iast.json')
console.log('30 B')
assert.include(payload[0][0].meta['_dd.iast.json'], '"COMMAND_INJECTION"')
console.log('40 B')
})
verifySpan(payload, span => {
console.log('20 B')
assert.property(span.meta, '_dd.iast.json')
console.log('30 B')
assert.include(span.meta['_dd.iast.json'], '"COMMAND_INJECTION"')
console.log('40 B')
})
}, null, 1, true)
})
})
})
Expand Down

0 comments on commit 03b53f1

Please sign in to comment.