From 31da3fba8f87e39277387726e4b4d1526d02bf35 Mon Sep 17 00:00:00 2001 From: Yury Lebedev Date: Thu, 5 Sep 2024 15:13:23 +0200 Subject: [PATCH] Add guard clause to GraphQL gateway watcher --- .../appsec/contrib/graphql/gateway/watcher.rb | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/datadog/appsec/contrib/graphql/gateway/watcher.rb b/lib/datadog/appsec/contrib/graphql/gateway/watcher.rb index 1ddf89c1c98..505bd32afb2 100644 --- a/lib/datadog/appsec/contrib/graphql/gateway/watcher.rb +++ b/lib/datadog/appsec/contrib/graphql/gateway/watcher.rb @@ -27,27 +27,27 @@ def watch_multiplex(gateway = Instrumentation.gateway) scope = AppSec::Scope.active_scope - if scope - AppSec::Reactive::Operation.new('graphql.multiplex') do |op| - GraphQL::Reactive::Multiplex.subscribe(op, scope.processor_context) do |result| - event = { - waf_result: result, - trace: scope.trace, - span: scope.service_entry_span, - multiplex: gateway_multiplex, - actions: result.actions - } + return stack.call(gateway_multiplex.arguments) unless scope - if scope.service_entry_span - scope.service_entry_span.set_tag('appsec.blocked', 'true') if result.actions.include?('block') - scope.service_entry_span.set_tag('appsec.event', 'true') - end + AppSec::Reactive::Operation.new('graphql.multiplex') do |op| + GraphQL::Reactive::Multiplex.subscribe(op, scope.processor_context) do |result| + event = { + waf_result: result, + trace: scope.trace, + span: scope.service_entry_span, + multiplex: gateway_multiplex, + actions: result.actions + } - scope.processor_context.events << event + if scope.service_entry_span + scope.service_entry_span.set_tag('appsec.blocked', 'true') if result.actions.include?('block') + scope.service_entry_span.set_tag('appsec.event', 'true') end - block = GraphQL::Reactive::Multiplex.publish(op, gateway_multiplex) + scope.processor_context.events << event end + + block = GraphQL::Reactive::Multiplex.publish(op, gateway_multiplex) end next [nil, [[:block, event]]] if block