-
Notifications
You must be signed in to change notification settings - Fork 377
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
Add AppSec::ActionHandler to unify action handling #4300
base: master
Are you sure you want to change the base?
Changes from all commits
53bf41a
f65767b
307cc2a
93506ec
06f2060
4d47360
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module AppSec | ||
# this module encapsulates functions for handling actions that libddawf returns | ||
module ActionsHandler | ||
module_function | ||
|
||
def handle(actions_hash) | ||
# handle actions according their precedence | ||
# stack and schema generation should be done before we throw an interrupt signal | ||
generate_stack(actions_hash['generate_stack']) if actions_hash.key?('generate_stack') | ||
generate_schema(actions_hash['generate_schema']) if actions_hash.key?('generate_schema') | ||
redirect_request(actions_hash['redirect_request']) if actions_hash.key?('redirect_request') | ||
block_request(actions_hash['block_request']) if actions_hash.key?('block_request') | ||
end | ||
|
||
def block_request(action_params) | ||
throw(Datadog::AppSec::Ext::INTERRUPT, action_params) | ||
end | ||
|
||
def redirect_request(action_params) | ||
throw(Datadog::AppSec::Ext::INTERRUPT, action_params) | ||
end | ||
|
||
def generate_stack(_action_params); end | ||
|
||
def generate_schema(_action_params); end | ||
|
||
def monitor(_action_params); end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ def watch | |
# This time we don't throw but use next | ||
def watch_multiplex(gateway = Instrumentation.gateway) | ||
gateway.watch('graphql.multiplex', :appsec) do |stack, gateway_multiplex| | ||
block = false | ||
event = nil | ||
context = AppSec::Context.active | ||
engine = AppSec::Reactive::Engine.new | ||
|
@@ -39,13 +38,13 @@ def watch_multiplex(gateway = Instrumentation.gateway) | |
|
||
Datadog::AppSec::Event.tag_and_keep!(context, result) | ||
context.events << event | ||
|
||
Datadog::AppSec::ActionsHandler.handle(result.actions) | ||
end | ||
|
||
block = GraphQL::Reactive::Multiplex.publish(engine, gateway_multiplex) | ||
GraphQL::Reactive::Multiplex.publish(engine, gateway_multiplex) | ||
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. In the files contained in the Reactive folder of each contrib (e.g. 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 would be done in a separate PR to reduce the amount of changes here. We want to fully get rid of the Reactive Engine, since it only has a instrumentation-local scope and didn't work as intended |
||
end | ||
|
||
next [nil, [[:block, event]]] if block | ||
|
||
stack.call(gateway_multiplex.arguments) | ||
end | ||
end | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, this PR also removes the creation of responses at framework level (e.g. GraphQL) to handle them all at Rack level ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, GraphQL instrumentation should only signal with
INTERRUPT
and leave response blocking to Rack