Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
vpellan committed Jan 9, 2025
1 parent 6e25c8f commit f79044e
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 42 deletions.
4 changes: 1 addition & 3 deletions lib/datadog/appsec/contrib/active_record/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def detect_sql_injection(sql, adapter_name)
scope.processor_context.events << event

# Include the stack trace if waf result includes it
if AppSec::StackTrace.include_stack_trace?(result)
AppSec::StackTrace.add_stack_trace(scope, result)
end
AppSec::StackTrace.add_stack_trace(scope, result) if AppSec::StackTrace.include_stack_trace?(result)
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/datadog/appsec/contrib/graphql/gateway/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def watch_multiplex(gateway = Instrumentation.gateway)
scope.processor_context.events << event

# Include the stack trace if waf result includes it
if AppSec::StackTrace.include_stack_trace?(result)
AppSec::StackTrace.add_stack_trace(scope, result)
end
AppSec::StackTrace.add_stack_trace(scope, result) if AppSec::StackTrace.include_stack_trace?(result)
end

block = GraphQL::Reactive::Multiplex.publish(engine, gateway_multiplex)
Expand Down
12 changes: 3 additions & 9 deletions lib/datadog/appsec/contrib/rack/gateway/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def watch_request(gateway = Instrumentation.gateway)
scope.processor_context.events << event

# Include the stack trace if waf result includes it
if AppSec::StackTrace.include_stack_trace?(result)
AppSec::StackTrace.add_stack_trace(scope, result)
end
AppSec::StackTrace.add_stack_trace(scope, result) if AppSec::StackTrace.include_stack_trace?(result)
end
end

Expand Down Expand Up @@ -89,9 +87,7 @@ def watch_response(gateway = Instrumentation.gateway)
scope.processor_context.events << event

# Include the stack trace if waf result includes it
if AppSec::StackTrace.include_stack_trace?(result)
AppSec::StackTrace.add_stack_trace(scope, result)
end
AppSec::StackTrace.add_stack_trace(scope, result) if AppSec::StackTrace.include_stack_trace?(result)
end
end

Expand Down Expand Up @@ -132,9 +128,7 @@ def watch_request_body(gateway = Instrumentation.gateway)
scope.processor_context.events << event

# Include the stack trace if waf result includes it
if AppSec::StackTrace.include_stack_trace?(result)
AppSec::StackTrace.add_stack_trace(scope, result)
end
AppSec::StackTrace.add_stack_trace(scope, result) if AppSec::StackTrace.include_stack_trace?(result)
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/datadog/appsec/contrib/rails/gateway/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def watch_request_action(gateway = Instrumentation.gateway)
scope.processor_context.events << event

# Include the stack trace if waf result includes it
if AppSec::StackTrace.include_stack_trace?(result)
AppSec::StackTrace.add_stack_trace(scope, result)
end
AppSec::StackTrace.add_stack_trace(scope, result) if AppSec::StackTrace.include_stack_trace?(result)
end
end

Expand Down
8 changes: 2 additions & 6 deletions lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def watch_request_dispatch(gateway = Instrumentation.gateway)
scope.processor_context.events << event

# Include the stack trace if waf result includes it
if AppSec::StackTrace.include_stack_trace?(result)
AppSec::StackTrace.add_stack_trace(scope, result)
end
AppSec::StackTrace.add_stack_trace(scope, result) if AppSec::StackTrace.include_stack_trace?(result)
end
end

Expand Down Expand Up @@ -87,9 +85,7 @@ def watch_request_routed(gateway = Instrumentation.gateway)
scope.processor_context.events << event

# Include the stack trace if waf result includes it
if AppSec::StackTrace.include_stack_trace?(result)
AppSec::StackTrace.add_stack_trace(scope, result)
end
AppSec::StackTrace.add_stack_trace(scope, result) if AppSec::StackTrace.include_stack_trace?(result)
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/datadog/appsec/monitor/gateway/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def watch_user_id(gateway = Instrumentation.gateway)
scope.processor_context.events << event

# Include the stack trace if waf result includes it
if AppSec::StackTrace.include_stack_trace?(result)
AppSec::StackTrace.add_stack_trace(scope, result)
end
AppSec::StackTrace.add_stack_trace(scope, result) if AppSec::StackTrace.include_stack_trace?(result)
end
end

Expand Down
30 changes: 15 additions & 15 deletions lib/datadog/appsec/stack_trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ class StackTrace
def initialize(id, stack_trace, message: nil)
@id = id
@message = message
if stack_trace
@frames = stack_trace.each_with_index.map do |frame, index|
Frame.new(
index,
text: frame.to_s,
file: frame.absolute_path, # path will show 'main' instead of the actual file
line: frame.lineno,
function: frame.base_label # label will show 'block in function' instead of just 'function'
)
end
else
@frames = []
end
@frames = if stack_trace
stack_trace.each_with_index.map do |frame, index|
Frame.new(
index,
text: frame.to_s,
file: frame.absolute_path, # path will show 'main' instead of the actual file
line: frame.lineno,
function: frame.base_label # label will show 'block in function' instead of just 'function'
)
end
else
[]
end
end

def to_h
Expand Down Expand Up @@ -61,7 +61,7 @@ def from_waf_result(waf_result)
# caller_locations without params always returns an array but rbs still thinks it can be nil
stack_frames.reject! { |loc| loc.path && loc.path.include?('lib/datadog') }
stack_trace_id = waf_result.actions['generate_stack']['stack_id']
stack_trace = AppSec::StackTrace.new(stack_trace_id, stack_frames)
AppSec::StackTrace.new(stack_trace_id, stack_frames)
end

# Whether to include the stack trace in the event
Expand All @@ -76,7 +76,7 @@ def add_stack_trace(scope, result)
service_entry_operation = scope.trace || scope.service_entry_span

unless service_entry_operation
Datadog.logger.debug { "Cannot find trace or service entry span to add stack trace" }
Datadog.logger.debug { 'Cannot find trace or service entry span to add stack trace' }
return
end

Expand Down

0 comments on commit f79044e

Please sign in to comment.