From 50c1d717b074be299dec4d8c0880bab20d1077d1 Mon Sep 17 00:00:00 2001 From: Prateek Sen Date: Thu, 26 Dec 2024 11:04:34 +0530 Subject: [PATCH] nil check for event processor and disable security on websocket close --- lib/newrelic_security/agent/control/collector.rb | 2 +- lib/newrelic_security/agent/control/websocket_client.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/newrelic_security/agent/control/collector.rb b/lib/newrelic_security/agent/control/collector.rb index 1fb0de9..d67383c 100644 --- a/lib/newrelic_security/agent/control/collector.rb +++ b/lib/newrelic_security/agent/control/collector.rb @@ -60,7 +60,7 @@ def collect(case_type, args, event_category = nil, **keyword_args) event.lineNumber = stk[0].lineno end event.stacktrace = stk[0..user_frame_index].map(&:to_s) - NewRelic::Security::Agent.agent.event_processor.send_event(event) + NewRelic::Security::Agent.agent.event_processor&.send_event(event) if event.httpRequest[:headers].key?(NR_CSEC_FUZZ_REQUEST_ID) && event.apiId == event.httpRequest[:headers][NR_CSEC_FUZZ_REQUEST_ID].split(COLON_IAST_COLON)[0] && NewRelic::Security::Agent.agent.iast_client.completed_requests[event.parentId] NewRelic::Security::Agent.agent.iast_client.completed_requests[event.parentId] << event.id end diff --git a/lib/newrelic_security/agent/control/websocket_client.rb b/lib/newrelic_security/agent/control/websocket_client.rb index f0f7e55..76bcfb1 100644 --- a/lib/newrelic_security/agent/control/websocket_client.rb +++ b/lib/newrelic_security/agent/control/websocket_client.rb @@ -141,6 +141,7 @@ def send(message) end def close(reconnect = true) + NewRelic::Security::Agent.config.disable_security NewRelic::Security::Agent.logger.info "Flushing eventQ (#{NewRelic::Security::Agent.agent.event_processor.eventQ.size} events) and closing websocket connection" NewRelic::Security::Agent.agent.event_processor&.eventQ&.clear @iast_client&.iast_data_transfer_request_processor_thread&.kill