Skip to content

Commit

Permalink
New lfi test
Browse files Browse the repository at this point in the history
  • Loading branch information
iunanua committed Sep 17, 2024
1 parent 1742560 commit 87ea5b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 1 addition & 3 deletions packages/datadog-instrumentations/src/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,7 @@ function createWrapFunction (prefix = '', override = '') {
if (name.includes('Sync')) {
finish(error)
throw error
}

if (cb) {
} else if (cb) {
arguments[lastIndex](error)
return
} else {
Expand Down
21 changes: 19 additions & 2 deletions packages/dd-trace/test/appsec/rasp/lfi.express.plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,24 @@ describe('RASP - lfi', () => {
return checkRaspExecutedAndNotThreat(agent, false)
})

it('Should detect threat if path is absolute', async () => {
it('Should not detect threat using a path not present in the request', async () => {
app = (req, res) => {
try {
require('fs').statSync('/test.file')
} catch (e) {
if (e.message === 'DatadogRaspAbortError') {
res.writeHead(418)
}
}
res.end('end')
}

await axios.get('/')

return checkRaspExecutedAndNotThreat(agent)
})

it('Should detect threat using a sync method', async () => {
app = (req, res) => {
try {
require('fs').statSync(req.query.file)
Expand All @@ -99,7 +116,7 @@ describe('RASP - lfi', () => {
return testBlockingRequest()
})

it('Should detect threat using await', async () => {
it('Should detect threat using async/await', async () => {
app = async (req, res) => {
try {
await require('fs').stat(req.query.file)
Expand Down

0 comments on commit 87ea5b4

Please sign in to comment.