diff --git a/aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagator.java b/aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagator.java index 2ce17875b..c61ff6ecc 100644 --- a/aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagator.java +++ b/aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagator.java @@ -290,7 +290,8 @@ private static String parseShortTraceId(String xrayTraceId) { int secondDelimiter = xrayTraceId.indexOf(TRACE_ID_DELIMITER, firstDelimiter + 2); if (firstDelimiter != TRACE_ID_DELIMITER_INDEX_1 || secondDelimiter == -1 - || secondDelimiter > TRACE_ID_DELIMITER_INDEX_2) { + || secondDelimiter > TRACE_ID_DELIMITER_INDEX_2 + || xrayTraceId.length() < secondDelimiter + 25) { return TraceId.getInvalid(); } diff --git a/aws-xray-propagator/src/test/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagatorTest.java b/aws-xray-propagator/src/test/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagatorTest.java index 452c7c1bd..a76a529f1 100644 --- a/aws-xray-propagator/src/test/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagatorTest.java +++ b/aws-xray-propagator/src/test/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagatorTest.java @@ -288,7 +288,7 @@ void extract_InvalidTraceId() { } @Test - void extract_InvalidTraceId_Size() { + void extract_InvalidTraceId_Size_TooBig() { Map invalidHeaders = new LinkedHashMap<>(); invalidHeaders.put( TRACE_HEADER_KEY, @@ -297,6 +297,16 @@ void extract_InvalidTraceId_Size() { verifyInvalidBehavior(invalidHeaders); } + @Test + void extract_InvalidTraceId_Size_TooShort() { + Map invalidHeaders = new LinkedHashMap<>(); + invalidHeaders.put( + TRACE_HEADER_KEY, + "Root=1-64fbd5a9-2202432c9dfed25ae1e6996;Parent=53995c3f42cd8ad8;Sampled=0"); + + verifyInvalidBehavior(invalidHeaders); + } + @Test void extract_InvalidSpanId() { Map invalidHeaders = new LinkedHashMap<>();