Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Closes #354 - Ignores B3 headers if invalid values are provided #355

Merged

Conversation

jpkrohling
Copy link
Collaborator

No description provided.

@ghost ghost assigned jpkrohling Feb 26, 2018
@ghost ghost added the review label Feb 26, 2018
@@ -60,8 +60,8 @@ public void inject(SpanContext spanContext, TextMap carrier) {

@Override
public SpanContext extract(TextMap carrier) {
Long traceId = null;
Long spanId = null;
long traceId = -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HexCodec.lowerHexToUnsignedLong("ffffffffffffffffffffffffffffffff") returns -1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does a method named lowerHexToUnsignedLong returns a signed long as a valid response? O_O

Signed-off-by: Tomasz Adamski <tadamski@wikia-inc.com>
@jpkrohling
Copy link
Collaborator Author

@pavolloffay , I changed the PR to use null instead of -1, as it didn't really occur to me that they were fitting a 64 bit into Java's 32 bit long.

Could you please re-review and merge? Looks like the debug flag is safe, but I couldn't find where the baggage might be vulnerable (see #354 (comment))

@codecov
Copy link

codecov bot commented Feb 27, 2018

Codecov Report

Merging #355 into master will increase coverage by 0.32%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #355      +/-   ##
============================================
+ Coverage      84.5%   84.83%   +0.32%     
- Complexity      590      597       +7     
============================================
  Files            92       92              
  Lines          2388     2387       -1     
  Branches        272      272              
============================================
+ Hits           2018     2025       +7     
+ Misses          270      266       -4     
+ Partials        100       96       -4
Impacted Files Coverage Δ Complexity Δ
...va/com/uber/jaeger/propagation/B3TextMapCodec.java 83.87% <100%> (+3.22%) 14 <0> (+2) ⬆️
...ain/java/com/uber/jaeger/propagation/HexCodec.java 72.5% <100%> (+9.08%) 12 <0> (+3) ⬆️
...jaeger/reporters/protocols/ThriftUdpTransport.java 86.44% <0%> (+5.08%) 16% <0%> (+2%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 581e20f...0847ca9. Read the comment docs.

assertEquals(HexCodec.lowerHexToUnsignedLong(lower64Bits), context.getTraceId());
assertEquals(HexCodec.lowerHexToUnsignedLong(lower64Bits), context.getSpanId());
assertNotNull(HexCodec.lowerHexToUnsignedLong(lower64Bits));
assertEquals((long) HexCodec.lowerHexToUnsignedLong(lower64Bits), context.getTraceId());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit there is Long.longValue()

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.isNull;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit unused and the above too

…rovided

Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
@jpkrohling jpkrohling force-pushed the 354-DontThrowExceptionOnBadInput branch from b84f4a6 to 0847ca9 Compare February 27, 2018 10:47
@pavolloffay pavolloffay merged commit cf99e75 into jaegertracing:master Feb 27, 2018
@ghost ghost removed the review label Feb 27, 2018
Copy link
Contributor

@tmszdmsk tmszdmsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It covers test cases I've prepared but I am still concerned about bugs we didn't detect yet. I would sleep better if there would be some try-catch-all block that fallbacks to "no context" in case of failure.

It can be also implemented as a decorator for composability.

*/
static long lowerHexToUnsignedLong(String lowerHex) {
static Long lowerHexToUnsignedLong(String lowerHex) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, Optional would be more obvious. However I understand that some like to "optimise" code with nulls

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, this tradeoff was made to maintain Java 6 compatibility without adding/writing an optional back port.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it. I didn't expect to have different lang level in test and main. Makes sense ;)

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for test case failure readability it should be implemented as second test method parameter + cartesian product in @DataProvidrer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addressed that in #358

@yurishkuro
Copy link
Member

Why is this a good change? There's another PR #359 that catches and logs all exceptions in the codecs. I think it's better to log an error saying that the inbound trace context was malformed than to silently ignore it, which makes it much harder for the user to figure out what's going on.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants