-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Allow request headers in HttpInputSource in native and MSQ Ingestion #16974
Allow request headers in HttpInputSource in native and MSQ Ingestion #16974
Conversation
Adding more tests and coverage. |
Please also add a corresponding runtime property to whitelist what header keys are allowed. The default can be empty and thus no header is allowed. These free-form property maps can create security holes. |
That runtime property should be added to |
processing/src/main/java/org/apache/druid/data/input/impl/HttpEntity.java
Fixed
Show fixed
Hide fixed
|
||
@JsonCreator | ||
public HttpInputSource( | ||
@JsonProperty("uris") List<URI> uris, | ||
@JsonProperty("httpAuthenticationUsername") @Nullable String httpAuthenticationUsername, | ||
@JsonProperty("httpAuthenticationPassword") @Nullable PasswordProvider httpAuthenticationPasswordProvider, | ||
@JsonProperty(SYSTEM_FIELDS_PROPERTY) @Nullable SystemFields systemFields, | ||
@JsonProperty("additionalHeaders") @Nullable Map<String, String> headersMap, |
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.
we should rename this to requestHeaders
everywhere.
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.
Minor comments. Looks good otherwise.
throws IOException | ||
{ | ||
final URLConnection urlConnection = object.toURL().openConnection(); | ||
if (requestHeaders.size() > 0) { |
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.
also need to check that requestHeaders is not null.
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 not, then requestHeaders is not nullable.
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.
fixed
@@ -64,13 +66,15 @@ public class HttpInputSource | |||
private final PasswordProvider httpAuthenticationPasswordProvider; | |||
private final SystemFields systemFields; | |||
private final HttpInputSourceConfig config; | |||
private final Map<String, String> headersMap; |
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.
private final Map<String, String> headersMap; | |
private final Map<String, String> requestHeaders; |
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.
fixed
if (!config.getAllowedHeaders().isEmpty() && headersMap.size() > 0) { | ||
Set<String> forbiddenHeaderSet = headersMap.keySet() | ||
.stream() | ||
.map(StringUtils::toLowerCase) | ||
.filter(h -> !config.getAllowedHeaders().contains(h)) | ||
.collect(Collectors.toSet()); | ||
if (!forbiddenHeaderSet.isEmpty()) { | ||
throw new IAE("Got forbidden headers %s, allowed headers are only %s ", | ||
forbiddenHeaderSet, config.getAllowedHeaders()); | ||
} | ||
} |
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.
this could be simplified to
for key in headersMap
if (!config.allowedHeaders.contains(key))
throw new IAE(" Header [%s] is not allowed to be set. Only headers are allowed are [%s]. You can allow the headers by changing property <insert property name> ",
key, config.getAllowedHeaders());
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.
Also please use InvalidInput.exception.
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.
fixed
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.
can you add one test with non-empty headers map?
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.
added test
inputStreamPartial = HttpEntity.openInputStream(url, "", null, 5); | ||
inputStream = HttpEntity.openInputStream(url, "", null, 0, Collections.emptyMap()); | ||
inputStreamPartial = HttpEntity.openInputStream(url, "", null, 5, Collections.emptyMap()); | ||
inputStream.skip(5); |
Check notice
Code scanning / CodeQL
Ignored error status of call Note test
{ | ||
if (config.getAllowedHeaders().size() > 0) { | ||
for (Map.Entry<String, String> entry : requestHeaders.entrySet()) { | ||
if (!config.getAllowedHeaders().contains(StringUtils.toLowerCase(entry.getKey()))) { |
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.
are the keys in allowedHeaders always lower case?
Yes, they are mapped as lowercase and stored in maps
…On Wed, Sep 11, 2024, 7:56 PM Abhishek Agarwal ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
processing/src/main/java/org/apache/druid/data/input/impl/HttpInputSource.java
<#16974 (comment)>:
> @@ -100,6 +98,27 @@ public static void throwIfInvalidProtocols(HttpInputSourceConfig config, List<UR
}
}
+ public static void throwIfForbiddenHeaders(HttpInputSourceConfig config, Map<String, String> requestHeaders)
+ {
+ if (config.getAllowedHeaders().size() > 0) {
+ for (Map.Entry<String, String> entry : requestHeaders.entrySet()) {
+ if (!config.getAllowedHeaders().contains(StringUtils.toLowerCase(entry.getKey()))) {
are the keys in allowedHeaders always lower case?
—
Reply to this email directly, view it on GitHub
<#16974 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABFU6HWTHE5CVEUTEYTOB5LZWD7GTAVCNFSM6AAAAABNJEAG2WVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDEOJZGEYTSMZVGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
…pache#16974) Support for adding the request headers in http input source. we can now pass the additional headers as json in both native and MSQ.
Description
PR for adding the request headers in http input source. we can now pass the additional headers as json in both native and MSQ.
Examples below.
Release note
This PR has: