This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* tests for malicious input for B3TextMapCodec Signed-off-by: Tomasz Adamski <tadamski@wikia-inc.com> * Closes #354 - Ignores B3 headers if invalid values are provided Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
- Loading branch information
1 parent
581e20f
commit cf99e75
Showing
4 changed files
with
81 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
jaeger-core/src/test/java/com/uber/jaeger/propagation/B3TextMapCodecResiliencyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) 2016, Uber Technologies, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.uber.jaeger.propagation; | ||
|
||
import static org.junit.Assert.assertNull; | ||
|
||
import com.tngtech.java.junit.dataprovider.DataProvider; | ||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | ||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | ||
import com.uber.jaeger.SpanContext; | ||
import io.opentracing.propagation.TextMap; | ||
import java.util.Arrays; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(DataProviderRunner.class) | ||
public class B3TextMapCodecResiliencyTest { | ||
|
||
private B3TextMapCodec sut = new B3TextMapCodec(); | ||
|
||
@DataProvider | ||
public static Object[] maliciousInputs() { | ||
return new Object[] { | ||
"abcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbdabcbd", | ||
"", | ||
"ABCDEF", | ||
}; | ||
} | ||
|
||
@Test | ||
@UseDataProvider("maliciousInputs") | ||
public void shouldFallbackWhenMaliciousInput(String maliciousInput) { | ||
String validInput = "ffffffffffffffffffffffffffffffff"; | ||
TextMap maliciousCarrier = new B3TextMapCodecTest.DelegatingTextMap(); | ||
maliciousCarrier.put(B3TextMapCodec.TRACE_ID_NAME, validInput); | ||
maliciousCarrier.put(B3TextMapCodec.SPAN_ID_NAME, validInput); | ||
maliciousCarrier.put(B3TextMapCodec.PARENT_SPAN_ID_NAME, validInput); | ||
|
||
// everything is valid, except for one of the headers at a time: | ||
for (String header : Arrays.asList( | ||
B3TextMapCodec.TRACE_ID_NAME, | ||
B3TextMapCodec.SPAN_ID_NAME, | ||
B3TextMapCodec.PARENT_SPAN_ID_NAME)) { | ||
maliciousCarrier.put(header, maliciousInput); | ||
//when | ||
SpanContext extract = sut.extract(maliciousCarrier); | ||
|
||
//then | ||
assertNull(extract); | ||
|
||
maliciousCarrier.put(header, validInput); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters