Allow request headers in HttpInputSource in native and MSQ Ingestion#16974
Allow request headers in HttpInputSource in native and MSQ Ingestion#16974abhishekagarwal87 merged 12 commits intoapache:masterfrom
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 |
| @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.
we should rename this to requestHeaders everywhere.
abhishekagarwal87
left a comment
There was a problem hiding this comment.
Minor comments. Looks good otherwise.
| throws IOException | ||
| { | ||
| final URLConnection urlConnection = object.toURL().openConnection(); | ||
| if (requestHeaders.size() > 0) { |
There was a problem hiding this comment.
also need to check that requestHeaders is not null.
There was a problem hiding this comment.
if not, then requestHeaders is not nullable.
| 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.
| private final Map<String, String> headersMap; | |
| private final Map<String, String> requestHeaders; |
| 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.
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.
Also please use InvalidInput.exception.
There was a problem hiding this comment.
can you add one test with non-empty headers map?
| 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
| { | ||
| 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.
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: