-
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
Pass HTTP client IP to WAF #2316
Merged
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ca4d708
Pass HTTP client IP to WAF
lloeki e3d11c7
Add basic content negotiation support for blocking
lloeki 042c2f0
Change expected 403 to 200 when appsec is disabled
lloeki 8e226dc
Change reset with around to after
lloeki 0328405
Enable AppSec IP blocking test for Sinatra and Rails
lloeki bfe1f0a
Improve blocking code
lloeki a22e6fb
Fix guard clause early return on Processor init
lloeki 1f68f94
Comply with linter
lloeki 5f25e24
Split HTTP_ACCEPT only once
lloeki ada420e
Add comment regarding experimental configurable
lloeki f8de0e2
Factor out SQLI rule in specs
lloeki e799022
Indent class-level methods
lloeki b4c2694
Remove extra spec declaration line
lloeki f7b43e9
Disable AppSec rails contrib tests
lloeki 9ec5ec3
Fix incorrect spec target
lloeki 9314c7a
Use head instead of render for AppSec Rails specs
lloeki ba2147c
Patch ActionController::Metal instead of ActionController::Instrument…
lloeki 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
{"errors": [{"title": "You've been blocked", "detail": "Sorry, you cannot access this page. Please contact the customer service team. Security provided by Datadog."}]} |
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,5 @@ | ||
You've been blocked | ||
lloeki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Sorry, you cannot access this page. Please contact the customer service team. | ||
|
||
Security provided by Datadog. |
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
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
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
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,54 @@ | ||
# typed: false | ||
|
||
require_relative 'assets' | ||
|
||
module Datadog | ||
module AppSec | ||
# AppSec response | ||
class Response | ||
attr_reader :status, :headers, :body | ||
|
||
def initialize(status:, headers: {}, body: []) | ||
@status = status | ||
@headers = headers | ||
@body = body | ||
end | ||
|
||
def to_rack | ||
[status, headers, body] | ||
end | ||
|
||
def to_sinatra_response | ||
::Sinatra::Response.new(body, status, headers) | ||
end | ||
|
||
def to_action_dispatch_response | ||
::ActionDispatch::Response.new(status, headers, body) | ||
end | ||
|
||
class << self | ||
def negotiate(env) | ||
Response.new( | ||
status: 403, | ||
headers: { 'Content-Type' => 'text/html' }, | ||
body: [Datadog::AppSec::Assets.blocked(format: format(env))] | ||
) | ||
end | ||
|
||
private | ||
|
||
def format(env) | ||
format = env['HTTP_ACCEPT'] && env['HTTP_ACCEPT'].split(',').any? do |accept| | ||
if accept.start_with?('text/html') | ||
break :html | ||
elsif accept.start_with?('application/json') | ||
break :json | ||
end | ||
end | ||
|
||
format || :text | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
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.
Did you mean to disable JRuby for Tracing tests?
bundle exec appraisal rails32-mysql2 rake spec:rails
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.
Hmm, good catch @marcotc, I think I fat-fingered that one.
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.
I think the fat finger was in the original PR that added it? This actually seems duplicated from the non-appsec section 😱
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.
Oh, actually:
☝️ This diff removed an extra line that was duplicated.
☝️ This diff had the corresponding line that was duplicated. Notice though that both are
spec:rails
... instead ofspec:appsec:rails
, which is the actual mistake!