Skip to content

Commit

Permalink
in_splunk: Handle authrozation header more precisely for HTTP1.1
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
  • Loading branch information
cosmo0920 committed May 31, 2024
1 parent fe4507f commit c08585c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions plugins/in_splunk/splunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ static int in_splunk_exit(void *data, struct flb_config *config)

ctx = data;

if (ctx->ingested_auth_header != NULL) {
flb_sds_destroy(ctx->ingested_auth_header);
}

if (ctx != NULL) {
splunk_config_destroy(ctx);
}
Expand Down
19 changes: 15 additions & 4 deletions plugins/in_splunk/splunk_prot.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ static flb_sds_t tag_key(struct flb_splunk *ctx, msgpack_object *map)
return NULL;
}

static void reset_ingested_auth_header(struct flb_splunk *ctx)
{
if (ctx->ingested_auth_header != NULL) {
flb_sds_destroy(ctx->ingested_auth_header);
}
}

/*
* Process a raw text payload for Splunk HEC requests, uses the delimited character to split records,
* return the number of processed bytes
Expand Down Expand Up @@ -582,7 +589,8 @@ static int process_hec_payload(struct flb_splunk *ctx, struct splunk_conn *conn,
header_auth = &session->parser.headers[MK_HEADER_AUTHORIZATION];
if (header_auth->key.data != NULL) {
if (strncasecmp(header_auth->val.data, "Splunk ", 7) == 0) {
ctx->ingested_auth_header = header_auth->val.data;
reset_ingested_auth_header(ctx);
ctx->ingested_auth_header = flb_sds_create_len(header_auth->val.data, header_auth->val.len);
}
}

Expand Down Expand Up @@ -647,7 +655,8 @@ static int process_hec_raw_payload(struct flb_splunk *ctx, struct splunk_conn *c
header_auth = &session->parser.headers[MK_HEADER_AUTHORIZATION];
if (header_auth->key.data != NULL) {
if (strncasecmp(header_auth->val.data, "Splunk ", 7) == 0) {
ctx->ingested_auth_header = header_auth->val.data;
reset_ingested_auth_header(ctx);
ctx->ingested_auth_header = flb_sds_create_len(header_auth->val.data, header_auth->val.len);
}
}

Expand Down Expand Up @@ -1001,7 +1010,8 @@ static int process_hec_payload_ng(struct flb_http_request *request,

ret = flb_hash_table_get(request->headers, "authorization", 13, (void **)&auth_header, &size);
if (ret != 0) {
ctx->ingested_auth_header = auth_header;
reset_ingested_auth_header(ctx);
ctx->ingested_auth_header = flb_sds_create_len(auth_header, size);
}

if (request->body == NULL || cfl_sds_len(request->body) <= 0) {
Expand Down Expand Up @@ -1034,7 +1044,8 @@ static int process_hec_raw_payload_ng(struct flb_http_request *request,

ret = flb_hash_table_get(request->headers, "authorization", 13, (void **)&auth_header, &size);
if (ret != 0) {
ctx->ingested_auth_header = auth_header;
reset_ingested_auth_header(ctx);
ctx->ingested_auth_header = flb_sds_create_len(auth_header, size);
}

if (request->body == NULL || cfl_sds_len(request->body) == 0) {
Expand Down

0 comments on commit c08585c

Please sign in to comment.