Skip to content
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

Merged
merged 12 commits into from
Jan 20, 2025

Conversation

y9v
Copy link
Member

@y9v y9v commented Jan 16, 2025

What does this PR do?
It adds Datadog::AppSec::ActionHandler module and unifies blocked response generation.

https://github.com/DataDog/libddwaf/blob/master/UPGRADING.md#action-semantics
https://github.com/DataDog/appsec-diagrams/blob/main/action-handling.md

Motivation:
We want to have a simple and unified way of handling libddwaf actions.

Change log entry
None.

Additional Notes:
Since Sinatra and Rails instrumentations always insert Datadog::AppSec::Contrib::Rack::RequestMiddleware, we don't need to catch interrupt signals anywhere other than in this Rack Middleware.

How to test the change?
CI and manual testing with app generator.

@y9v y9v self-assigned this Jan 16, 2025
@github-actions github-actions bot added integrations Involves tracing integrations appsec Application Security monitoring product labels Jan 16, 2025
lib/datadog/appsec/action_handler.rb Outdated Show resolved Hide resolved
lib/datadog/appsec/action_handler.rb Outdated Show resolved Hide resolved
lib/datadog/appsec/action_handler.rb Outdated Show resolved Hide resolved
lib/datadog/appsec/action_handler.rb Outdated Show resolved Hide resolved
lib/datadog/appsec/response.rb Show resolved Hide resolved
lib/datadog/appsec/response.rb Show resolved Hide resolved
lib/datadog/appsec/action_handler.rb Outdated Show resolved Hide resolved
@datadog-datadog-prod-us1
Copy link
Contributor

datadog-datadog-prod-us1 bot commented Jan 16, 2025

Datadog Report

Branch report: appsec-add-action-handler
Commit report: 11512de
Test service: dd-trace-rb

✅ 0 Failed, 22064 Passed, 1477 Skipped, 5m 32.97s Total Time

@pr-commenter
Copy link

pr-commenter bot commented Jan 16, 2025

Benchmarks

Benchmark execution time: 2025-01-20 15:52:20

Comparing candidate commit 11512de in PR branch appsec-add-action-handler with baseline commit 41dc832 in branch master.

Found 1 performance improvements and 0 performance regressions! Performance is the same for 30 metrics, 2 unstable metrics.

scenario:profiler - sample timeline=false

  • 🟩 throughput [+0.436op/s; +0.445op/s] or [+7.827%; +7.983%]

@codecov-commenter
Copy link

codecov-commenter commented Jan 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.71%. Comparing base (41dc832) to head (11512de).
Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4300   +/-   ##
=======================================
  Coverage   97.71%   97.71%           
=======================================
  Files        1358     1359    +1     
  Lines       82501    82477   -24     
  Branches     4223     4198   -25     
=======================================
- Hits        80614    80591   -23     
+ Misses       1887     1886    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@y9v y9v force-pushed the appsec-add-action-handler branch from 5d7a7f9 to 3343f03 Compare January 17, 2025 09:37
@y9v y9v marked this pull request as ready for review January 17, 2025 11:15
@y9v y9v requested review from a team as code owners January 17, 2025 11:15
@y9v y9v requested a review from vpellan January 17, 2025 15:12
y9v added 6 commits January 17, 2025 16:53
Because we need to handle actions according their precedence.
We want to test that ActionsHandler handles actions correctly according
their precedence.
These examples have to be rewritten with Hash#merge, since older
versions of Ruby do not support double-splat operator.
@y9v y9v force-pushed the appsec-add-action-handler branch from 4c28ff6 to 4d47360 Compare January 17, 2025 15:53
Copy link
Member

@Strech Strech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the overall change looks good and solid to use as an intermediate step to encapsulate the leaked logic 👍🏼

lib/datadog/appsec/actions_handler.rb Outdated Show resolved Hide resolved
lib/datadog/appsec/contrib/graphql/appsec_trace.rb Outdated Show resolved Hide resolved
lib/datadog/appsec/contrib/rack/request_body_middleware.rb Outdated Show resolved Hide resolved
lib/datadog/appsec/response.rb Outdated Show resolved Hide resolved
sig/datadog/appsec/actions_handler.rbs Outdated Show resolved Hide resolved
spec/datadog/appsec/actions_handler_spec.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@vpellan vpellan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

y9v added 2 commits January 20, 2025 12:56
This method should replace both ActionsHandler#block_request and
ActionsHandler#redirect_request
@y9v y9v merged commit b33b1d6 into master Jan 20, 2025
378 checks passed
@y9v y9v deleted the appsec-add-action-handler branch January 20, 2025 16:30
@github-actions github-actions bot added this to the 2.10.0 milestone Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appsec Application Security monitoring product integrations Involves tracing integrations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants