-
Notifications
You must be signed in to change notification settings - Fork 166
[AppSec] Send ip addresses headers to the backend #1764
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
Changes from all commits
206fa08
81a0490
15428b8
519706f
2749803
0de0160
5ab9e25
9cd93c0
70badbc
5474803
87447df
fa82ff3
4fda7cc
e461244
0866b4d
3419144
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // <copyright file="ExtractedHeadersAndIpInfos.cs" company="Datadog"> | ||
| // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. | ||
| // </copyright> | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| namespace Datadog.Trace.AppSec.Transports.Http | ||
| { | ||
| internal class ExtractedHeadersAndIpInfos | ||
| { | ||
| public ExtractedHeadersAndIpInfos(IDictionary<string, string> headersToSend, string address, int port) | ||
| { | ||
| HeadersToSend = headersToSend; | ||
| IpInfo = new IpInfo(address, port); | ||
| } | ||
|
|
||
| public ExtractedHeadersAndIpInfos(IDictionary<string, string> headersToSend, IpInfo ipInfo) | ||
| { | ||
| HeadersToSend = headersToSend; | ||
| IpInfo = ipInfo; | ||
| } | ||
|
|
||
| public IDictionary<string, string> HeadersToSend { get; } | ||
|
|
||
| public IpInfo IpInfo { get; } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| using System.Threading.Tasks; | ||
| using Datadog.Trace.AppSec.EventModel; | ||
| using Datadog.Trace.AppSec.Waf; | ||
| using Datadog.Trace.Util.Http; | ||
| using Microsoft.AspNetCore.Http; | ||
|
|
||
| namespace Datadog.Trace.AppSec.Transport.Http | ||
|
|
@@ -18,20 +19,25 @@ internal class HttpTransport : ITransport | |
|
|
||
| public HttpTransport(HttpContext context) => this.context = context; | ||
|
|
||
| public bool IsSecureConnection => context.Request.IsHttps; | ||
|
|
||
| public Func<string, string> GetHeader => key => context.Request.Headers[key]; | ||
|
|
||
| public Request Request() | ||
| { | ||
| var request = new Request | ||
| { | ||
| Method = context.Request.Method, | ||
| Path = context.Request.Path, | ||
| Scheme = context.Request.Scheme, | ||
| RemoteIp = context.Connection.RemoteIpAddress.ToString() | ||
| Url = context.Request.GetUrl() | ||
| }; | ||
|
|
||
| if (context.Request.Host.HasValue) | ||
| { | ||
| request.Host = context.Request.Host.ToString(); | ||
| request.Port = context.Request.Host.Port.GetValueOrDefault(); | ||
| request.RemoteIp = context.Connection.RemoteIpAddress.ToString(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason that this code doesn't make a call to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These properties should contain the peer ip address and port so in core we have them out of the box, but in framework, afaik it seems it's the |
||
| request.Port = context.Connection.RemotePort; | ||
| } | ||
|
|
||
| return 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.
FYI
CorrelationIdentifier.Envwill return an empty string as a fallback case. Will that input cause any issues?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.
It's supposed to have the content of the DD_ENV environment variable. We actually have some system tests failing because of it, I'm not sure if it's going to be empty sometimes even if DD_ENV is set?
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.
If DD_ENV is set, then this should receive that value. But if DD_ENV isn't set then I expect an empty string
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.
thanks!
so I think that's what we're expecting :)