Skip to content

Commit c91fdd7

Browse files
authored
fix: deobfuscate extralogging payload (#143)
* Deobfuscate extraLogging payload * v3.12.2
1 parent 10dca49 commit c91fdd7

File tree

4 files changed

+109
-3
lines changed

4 files changed

+109
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ or [JVM](https://github.com/Eppo-exp/java-server-sdk) SDKs.
1313

1414
```groovy
1515
dependencies {
16-
implementation 'cloud.eppo:sdk-common-jvm:3.12.1'
16+
implementation 'cloud.eppo:sdk-common-jvm:3.12.2'
1717
}
1818
```
1919

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = 'cloud.eppo'
9-
version = '3.12.2-SNAPSHOT'
9+
version = '3.12.2'
1010
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
1111

1212
java {

src/main/java/cloud/eppo/FlagEvaluator.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public static FlagEvaluationResult evaluateFlag(
8989

9090
if (isConfigObfuscated) {
9191
// Need to unobfuscate for the returned evaluation result
92-
allocationKey = base64Decode(allocationKey);
92+
if (allocationKey != null) {
93+
allocationKey = base64Decode(allocationKey);
94+
}
9395
if (variation != null) {
9496
String key = base64Decode(variation.getKey());
9597
EppoValue decodedValue = EppoValue.nullValue();
@@ -115,6 +117,22 @@ public static FlagEvaluationResult evaluateFlag(
115117
}
116118
variation = new Variation(key, decodedValue);
117119
}
120+
121+
// Deobfuscate extraLogging if present
122+
if (extraLogging != null && !extraLogging.isEmpty()) {
123+
Map<String, String> deobfuscatedExtraLogging = new HashMap<>();
124+
for (Map.Entry<String, String> entry : extraLogging.entrySet()) {
125+
try {
126+
String deobfuscatedKey = base64Decode(entry.getKey());
127+
String deobfuscatedValue = base64Decode(entry.getValue());
128+
deobfuscatedExtraLogging.put(deobfuscatedKey, deobfuscatedValue);
129+
} catch (Exception e) {
130+
// If deobfuscation fails, keep the original key-value pair
131+
deobfuscatedExtraLogging.put(entry.getKey(), entry.getValue());
132+
}
133+
}
134+
extraLogging = deobfuscatedExtraLogging;
135+
}
118136
}
119137

120138
return new FlagEvaluationResult(

src/test/java/cloud/eppo/FlagEvaluatorTest.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,94 @@ public void testObfuscated() {
356356
assertEquals("A", result.getVariation().getValue().stringValue());
357357
}
358358

359+
@Test
360+
public void testObfuscatedExtraLogging() {
361+
// Test that extraLogging is properly deobfuscated when isConfigObfuscated is true
362+
363+
Map<String, Variation> variations = createVariations("a");
364+
365+
// Create extraLogging with obfuscated keys and values
366+
Map<String, String> obfuscatedExtraLogging = new HashMap<>();
367+
obfuscatedExtraLogging.put(base64Encode("testKey"), base64Encode("testValue"));
368+
obfuscatedExtraLogging.put(base64Encode("anotherKey"), base64Encode("anotherValue"));
369+
370+
List<Split> splits = new ArrayList<>();
371+
splits.add(new Split("a", null, obfuscatedExtraLogging));
372+
373+
List<Allocation> allocations = createAllocations("test", splits);
374+
375+
// Create the base flag
376+
FlagConfig flag = createFlag(getMD5Hex("flag"), true, variations, allocations);
377+
378+
// Encode the variations (following the same pattern as the main obfuscated test)
379+
Map<String, Variation> encodedVariations = new HashMap<>();
380+
for (Map.Entry<String, Variation> variationEntry : variations.entrySet()) {
381+
String encodedVariationKey = base64Encode(variationEntry.getKey());
382+
Variation variationToEncode = variationEntry.getValue();
383+
Variation newVariation =
384+
new Variation(
385+
encodedVariationKey,
386+
EppoValue.valueOf(base64Encode(variationToEncode.getValue().stringValue())));
387+
encodedVariations.put(encodedVariationKey, newVariation);
388+
}
389+
390+
// Encode the allocations
391+
List<Allocation> encodedAllocations =
392+
allocations.stream()
393+
.map(
394+
allocationToEncode -> {
395+
allocationToEncode.setKey(base64Encode(allocationToEncode.getKey()));
396+
List<Split> encodedSplits =
397+
allocationToEncode.getSplits().stream()
398+
.map(
399+
splitToEncode ->
400+
new Split(
401+
base64Encode(splitToEncode.getVariationKey()),
402+
splitToEncode.getShards(),
403+
splitToEncode.getExtraLogging()))
404+
.collect(Collectors.toList());
405+
return new Allocation(
406+
allocationToEncode.getKey(),
407+
allocationToEncode.getRules(),
408+
allocationToEncode.getStartAt(),
409+
allocationToEncode.getEndAt(),
410+
encodedSplits,
411+
allocationToEncode.doLog());
412+
})
413+
.collect(Collectors.toList());
414+
415+
// Create the obfuscated flag
416+
FlagConfig obfuscatedFlag =
417+
new FlagConfig(
418+
flag.getKey(),
419+
flag.isEnabled(),
420+
flag.getTotalShards(),
421+
flag.getVariationType(),
422+
encodedVariations,
423+
encodedAllocations);
424+
425+
// Test with obfuscated config
426+
FlagEvaluationResult result =
427+
FlagEvaluator.evaluateFlag(obfuscatedFlag, "flag", "subject", new Attributes(), true);
428+
429+
// Verify that extraLogging is deobfuscated
430+
Map<String, String> extraLogging = result.getExtraLogging();
431+
assertNotNull(extraLogging);
432+
assertEquals("testValue", extraLogging.get("testKey"));
433+
assertEquals("anotherValue", extraLogging.get("anotherKey"));
434+
assertEquals(2, extraLogging.size());
435+
436+
// Test with non-obfuscated config to ensure no deobfuscation happens
437+
result = FlagEvaluator.evaluateFlag(obfuscatedFlag, "flag", "subject", new Attributes(), false);
438+
439+
// Verify that extraLogging remains obfuscated
440+
extraLogging = result.getExtraLogging();
441+
assertNotNull(extraLogging);
442+
assertEquals(base64Encode("testValue"), extraLogging.get(base64Encode("testKey")));
443+
assertEquals(base64Encode("anotherValue"), extraLogging.get(base64Encode("anotherKey")));
444+
assertEquals(2, extraLogging.size());
445+
}
446+
359447
private Map<String, Variation> createVariations(String key) {
360448
return createVariations(key, null, null);
361449
}

0 commit comments

Comments
 (0)