From 9ed8cf8dff4ba40b23dec0b8a43ac520fc623ee1 Mon Sep 17 00:00:00 2001 From: Tim Birkett <109664963+portswigger-tim@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:41:33 +0100 Subject: [PATCH] fix: handle unsupported content-types Signed-off-by: Tim Birkett <109664963+portswigger-tim@users.noreply.github.com> --- plugins/in_opentelemetry/opentelemetry_prot.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/in_opentelemetry/opentelemetry_prot.c b/plugins/in_opentelemetry/opentelemetry_prot.c index 4aa99dc435f..dd3d2c6cc21 100644 --- a/plugins/in_opentelemetry/opentelemetry_prot.c +++ b/plugins/in_opentelemetry/opentelemetry_prot.c @@ -2191,12 +2191,18 @@ static int process_payload_metrics_ng(struct flb_opentelemetry *ctx, cfl_sds_len(request->body) - 5, &offset); } - else { + else if (strcasecmp(request->content_type, "application/x-protobuf") == 0 || + strcasecmp(request->content_type, "application/json") == 0) { result = cmt_decode_opentelemetry_create(&decoded_contexts, request->body, cfl_sds_len(request->body), &offset); } + else { + flb_plg_error(ctx->ins, "Unsupported content type %s", request->content_type); + + return -1; + } if (result == CMT_DECODE_OPENTELEMETRY_SUCCESS) { cfl_list_foreach(iterator, &decoded_contexts) { @@ -2243,12 +2249,18 @@ static int process_payload_traces_proto_ng(struct flb_opentelemetry *ctx, cfl_sds_len(request->body) - 5, &offset); } - else { + else if (strcasecmp(request->content_type, "application/x-protobuf") == 0 || + strcasecmp(request->content_type, "application/json") == 0) { result = ctr_decode_opentelemetry_create(&decoded_context, request->body, cfl_sds_len(request->body), &offset); } + else { + flb_plg_error(ctx->ins, "Unsupported content type %s", request->content_type); + + return -1; + } if (result == 0) { result = flb_input_trace_append(ctx->ins, NULL, 0, decoded_context);