Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
iunanua committed Sep 12, 2024
1 parent bb85c99 commit 349155f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class PathTraversalAnalyzer extends InjectionAnalyzer {
// we could filter out all the nested fs.operations based on store.fs.root
// but if we spect a store in the context to be present we are going to exclude
// all out_of_the_request fs.operations
// AppsecFsPlugin must be enabled
if (ignoredOperations.includes(obj.operation) || outOfReqOrChild) return

const pathArguments = []
Expand Down
13 changes: 7 additions & 6 deletions packages/dd-trace/src/appsec/rasp/lfi.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { fsOperationStart } = require('../channels')
const { storage } = require('../../../../datadog-core')
const web = require('../../plugins/util/web')
const { enable: enableFsPlugin, disable: disableFsPlugin } = require('./fs-plugin')
const addresses = require('../addresses')
const { FS_OPERATION_PATH } = require('../addresses')
const waf = require('../waf')
const { RULE_TYPES, handleResult } = require('./utils')
const { block } = require('../blocking')
Expand Down Expand Up @@ -36,9 +36,9 @@ function analyzeLfi (ctx) {
const { req, fs, res } = store
if (!req || !fs) return

if (fs.root && !fs.opExcluded && shouldAnalyze(path)) {
if (shouldAnalyze(fs, path)) {
const persistent = {
[addresses.FS_OPERATION_PATH]: path
[FS_OPERATION_PATH]: path
}

const result = waf.run({ persistent }, req, RULE_TYPES.LFI)
Expand All @@ -49,14 +49,15 @@ function analyzeLfi (ctx) {

const { aborted, reason } = abortController.signal
if (aborted) {
block(req, res, web.root(req), null, reason.blockingAction)
block(req, res, web.root(req), null, reason?.blockingAction)
}
}
}
}

function shouldAnalyze (path) {
return isAbsolute(path) || path.includes('../')
function shouldAnalyze (fs, path) {
const notExcludedRootOp = !fs.opExcluded && fs.root
return notExcludedRootOp && (isAbsolute(path) || path.includes('../'))
}

module.exports = {
Expand Down

0 comments on commit 349155f

Please sign in to comment.