-
Notifications
You must be signed in to change notification settings - Fork 344
Fastify RASP support #6081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
simon-id
wants to merge
43
commits into
master
Choose a base branch
from
simon-id/fastify_rasp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fastify RASP support #6081
Changes from 36 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
cd9817b
push repro
simon-id 20650c1
remove the bug reproduction
simon-id a1f4453
put back newline
simon-id 935afdd
Merge branch 'master' into simon-id/fastify_rasp
simon-id 5863063
cleanup
simon-id 8f6bc80
Merge branch 'master' into simon-id/fastify_rasp
simon-id 199fa23
sort appsec channels alphabetically
simon-id 685b126
cleanup
simon-id 74f7afa
add fastify error channel
simon-id c688d27
block delegation system
simon-id 9cc997e
make req and res non-enumerable in DatadogRaspAbortError
simon-id 7fef0f1
do not delegateBlock when in process error handler
simon-id a712c63
Merge branch 'master' into simon-id/fastify_rasp
simon-id ecd9de9
add comment for later
simon-id 112b560
make rasp telemetry also work with delegateBlock
simon-id 9b444d9
cleanup
simon-id 02ce9e7
update rasp utils tests
simon-id 9a46ff7
update rasp tests
simon-id 01bd6b6
Merge branch 'master' into simon-id/fastify_rasp
simon-id a9a0bbe
add comment to explain promise handling
simon-id 7fc60fd
cleanup
simon-id 569e798
update rasp index test
simon-id dd4243e
cleanup
simon-id 32e068a
cleanup
simon-id 5a31d0d
cleanup
simon-id 2de92c2
update appsec index tests
simon-id c335d44
add comment
simon-id ce7ae85
ignore subsequent block delegations
simon-id aaf3db1
final
simon-id f57e0de
cleanup
simon-id 8ceda6d
cleanup
simon-id f77708e
cleanup
simon-id c7ba8ab
Merge branch 'master' into simon-id/fastify_rasp
simon-id cb9928c
remove plural name
simon-id 792360d
update blocking tests
simon-id 88eff65
misspelling
simon-id 81afd69
DRY
simon-id fd62980
rename functions for better clarity
simon-id 1f8a6a9
add last fastify plugin test for RASP blocking
simon-id aef5589
Merge branch 'master' into simon-id/fastify_rasp
simon-id 05f498e
add 2 more tests for good measure
simon-id 2db1a76
fix ssrf test
simon-id 78a91ba
Merge branch 'master' into simon-id/fastify_rasp
simon-id File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
'use strict' | ||
|
||
const web = require('../../plugins/util/web') | ||
const { setUncaughtExceptionCaptureCallbackStart, expressMiddlewareError } = require('../channels') | ||
const { block, isBlocked } = require('../blocking') | ||
const { | ||
setUncaughtExceptionCaptureCallbackStart, | ||
expressMiddlewareError, | ||
fastifyMiddlewareError | ||
} = require('../channels') | ||
const { block, delegateBlock, isBlocked } = require('../blocking') | ||
const ssrf = require('./ssrf') | ||
const sqli = require('./sql_injection') | ||
const lfi = require('./lfi') | ||
|
@@ -39,7 +43,7 @@ function findDatadogRaspAbortError (err, deep = 10) { | |
} | ||
|
||
function handleUncaughtExceptionMonitor (error) { | ||
if (!blockOnDatadogRaspAbortError({ error })) return | ||
if (!blockOnDatadogRaspAbortError({ error, isTopLevel: true })) return | ||
|
||
if (process.hasUncaughtExceptionCaptureCallback()) { | ||
// uncaughtException event is not executed when hasUncaughtExceptionCaptureCallback is true | ||
|
@@ -81,15 +85,21 @@ function handleUncaughtExceptionMonitor (error) { | |
} | ||
} | ||
|
||
function blockOnDatadogRaspAbortError ({ error }) { | ||
function blockOnDatadogRaspAbortError ({ error, isTopLevel }) { | ||
const abortError = findDatadogRaspAbortError(error) | ||
if (!abortError) return false | ||
|
||
const { req, res, blockingAction, raspRule, ruleTriggered } = abortError | ||
if (!isBlocked(res)) { | ||
const blocked = block(req, res, web.root(req), null, blockingAction) | ||
const blockFn = isTopLevel ? block : delegateBlock | ||
const blocked = blockFn(req, res, web.root(req), null, blockingAction) | ||
if (ruleTriggered) { | ||
updateRaspRuleMatchMetricTags(req, raspRule, true, blocked) | ||
// block() returns a bool, and delegateBlock() returns a promise | ||
// we use Promise.resolve() to handle both cases | ||
Promise.resolve(blocked).then(blocked => { | ||
uurien marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// TODO: bug: this should probably be called for each match even without block | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This TODO is not precise. We are calling to the method when the operation is not blocked. The bug is that if the operation is blocked but the request is not (for example: try catched blocked operation), we are not updating the metric neither with |
||
updateRaspRuleMatchMetricTags(req, raspRule, true, blocked) | ||
}) | ||
} | ||
} | ||
|
||
|
@@ -103,7 +113,9 @@ function enable (config) { | |
cmdi.enable(config) | ||
|
||
process.on('uncaughtExceptionMonitor', handleUncaughtExceptionMonitor) | ||
|
||
expressMiddlewareError.subscribe(blockOnDatadogRaspAbortError) | ||
fastifyMiddlewareError.subscribe(blockOnDatadogRaspAbortError) | ||
} | ||
|
||
function disable () { | ||
|
@@ -113,7 +125,9 @@ function disable () { | |
cmdi.disable() | ||
|
||
process.off('uncaughtExceptionMonitor', handleUncaughtExceptionMonitor) | ||
if (expressMiddlewareError.hasSubscribers) expressMiddlewareError.unsubscribe(blockOnDatadogRaspAbortError) | ||
|
||
expressMiddlewareError.unsubscribe(blockOnDatadogRaspAbortError) | ||
fastifyMiddlewareError.unsubscribe(blockOnDatadogRaspAbortError) | ||
} | ||
|
||
module.exports = { | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.