-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rasp lfi and iast using rasp fs-plugin * Add rasp lfi capability in RC * Handle aborted operations in fs instrumentation * enable test without express * cleanup and console log to debug test error * Do not throw * another test * Try increasing timeout * Enable debug again * Enable debug again * increase timeout a lot * increase timeout more * New lfi test * Increase test timeout * print all errors * remote debug info * Handle the different invocation cases * Handle non string properties * specify types to be analyzed * a bunch of tests * clean up * rasp lfi subs delayed (#4715) * Delay Appsec fs plugin subscription to fs:operations until the first req is received * disable rasp in tests * fix tests recursive call * Avoid multiple subscriptions to incomingHttpRequestStart * another try * replace spy with stub * execute unsubscribe asynchronously * sinon.assert async * clarify comment * Use a constant * Do not enable rasp in some tests * Remove not needed config property * Rename properties * Test iast and rasp fs-plugin subscription order * Avoid multiple analyzeLfi subscriptions * Block synchronous operations * Include synchronous blocking integration test * Test refactor * rename test file * Cleanup
- Loading branch information
Showing
26 changed files
with
1,465 additions
and
30 deletions.
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
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
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
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,99 @@ | ||
'use strict' | ||
|
||
const Plugin = require('../../plugins/plugin') | ||
const { storage } = require('../../../../datadog-core') | ||
const log = require('../../log') | ||
|
||
const RASP_MODULE = 'rasp' | ||
const IAST_MODULE = 'iast' | ||
|
||
const enabledFor = { | ||
[RASP_MODULE]: false, | ||
[IAST_MODULE]: false | ||
} | ||
|
||
let fsPlugin | ||
|
||
function enterWith (fsProps, store = storage.getStore()) { | ||
if (store && !store.fs?.opExcluded) { | ||
storage.enterWith({ | ||
...store, | ||
fs: { | ||
...store.fs, | ||
...fsProps, | ||
parentStore: store | ||
} | ||
}) | ||
} | ||
} | ||
|
||
class AppsecFsPlugin extends Plugin { | ||
enable () { | ||
this.addSub('apm:fs:operation:start', this._onFsOperationStart) | ||
this.addSub('apm:fs:operation:finish', this._onFsOperationFinishOrRenderEnd) | ||
this.addSub('tracing:datadog:express:response:render:start', this._onResponseRenderStart) | ||
this.addSub('tracing:datadog:express:response:render:end', this._onFsOperationFinishOrRenderEnd) | ||
|
||
super.configure(true) | ||
} | ||
|
||
disable () { | ||
super.configure(false) | ||
} | ||
|
||
_onFsOperationStart () { | ||
const store = storage.getStore() | ||
if (store) { | ||
enterWith({ root: store.fs?.root === undefined }, store) | ||
} | ||
} | ||
|
||
_onResponseRenderStart () { | ||
enterWith({ opExcluded: true }) | ||
} | ||
|
||
_onFsOperationFinishOrRenderEnd () { | ||
const store = storage.getStore() | ||
if (store?.fs?.parentStore) { | ||
storage.enterWith(store.fs.parentStore) | ||
} | ||
} | ||
} | ||
|
||
function enable (mod) { | ||
if (enabledFor[mod] !== false) return | ||
|
||
enabledFor[mod] = true | ||
|
||
if (!fsPlugin) { | ||
fsPlugin = new AppsecFsPlugin() | ||
fsPlugin.enable() | ||
} | ||
|
||
log.info(`Enabled AppsecFsPlugin for ${mod}`) | ||
} | ||
|
||
function disable (mod) { | ||
if (!mod || !enabledFor[mod]) return | ||
|
||
enabledFor[mod] = false | ||
|
||
const allDisabled = Object.values(enabledFor).every(val => val === false) | ||
if (allDisabled) { | ||
fsPlugin?.disable() | ||
|
||
fsPlugin = undefined | ||
} | ||
|
||
log.info(`Disabled AppsecFsPlugin for ${mod}`) | ||
} | ||
|
||
module.exports = { | ||
enable, | ||
disable, | ||
|
||
AppsecFsPlugin, | ||
|
||
RASP_MODULE, | ||
IAST_MODULE | ||
} |
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
Oops, something went wrong.