-
Notifications
You must be signed in to change notification settings - Fork 375
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
Introduce AppSec::Instrumentation::Gateway::Argument #2648
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c8a200f
Create Gateway::Argument
GustavoCaso b699563
replace primitive object for Instrumentation::Gateway::Parameters wit…
GustavoCaso 7bf099c
replace primitive object for Instrumentation::Gateway::Parameters wit…
GustavoCaso f55473c
replace OpenStruct with Datadog::AppSec::Instrumentation::Gateway::User
GustavoCaso 1f00790
add Sinatra::Gateway::Request
GustavoCaso 05e133d
provide the active context to Rack::Gateway::Response
GustavoCaso 9043bcd
fix rubocop issues
GustavoCaso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../instrumentation/gateway/argument' | ||
|
||
module Datadog | ||
module AppSec | ||
module Contrib | ||
module Rails | ||
module Gateway | ||
# Gateway Request argument. Normalized extration of data from ActionDispatch::Request | ||
class Request < Instrumentation::Gateway::Argument | ||
attr_reader :request | ||
|
||
def initialize(request) | ||
super | ||
@request = request | ||
end | ||
|
||
def env | ||
request.env | ||
end | ||
|
||
def headers | ||
request.headers | ||
end | ||
|
||
def host | ||
request.host | ||
end | ||
|
||
def user_agent | ||
request.user_agent | ||
end | ||
|
||
def remote_addr | ||
request.remote_addr | ||
end | ||
|
||
def parsed_body | ||
# force body parameter parsing, which is done lazily by Rails | ||
request.parameters | ||
|
||
# usually Hash<String,String> but can be a more complex | ||
# Hash<String,String||Array||Hash> when e.g coming from JSON or | ||
# with Rails advanced param square bracket parsing | ||
body = request.env['action_dispatch.request.request_parameters'] | ||
|
||
return if body.nil? | ||
|
||
body.reject do |k, _v| | ||
request.env['action_dispatch.request.path_parameters'].key?(k) | ||
end | ||
end | ||
|
||
def route_params | ||
excluded = [:controller, :action] | ||
|
||
request.env['action_dispatch.request.path_parameters'].reject do |k, _v| | ||
excluded.include?(k) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Datadog | ||
module AppSec | ||
module Contrib | ||
module Rails | ||
module Gateway | ||
class Request < Instrumentation::Gateway::Argument | ||
attr_reader request: untyped | ||
|
||
def initialize: (untyped request) -> void | ||
|
||
def env: () -> untyped | ||
|
||
def headers: () -> untyped | ||
|
||
def host: () -> untyped | ||
|
||
def user_agent: () -> untyped | ||
|
||
def remote_addr: () -> untyped | ||
|
||
def parsed_body: () -> (nil | untyped) | ||
|
||
def route_params: () -> untyped | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would it make sense to inherit from
Contrib::Rack::Gateway::Request
?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.
At first, I thought about, but since I saw we use the
Rack::RequestBody
directly in the Sinatra contrib folder I thought it would be ok.I'm happy to change it.