-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix org.json iast instrumentation test for latest dependency #8347
Open
jandro996
wants to merge
5
commits into
master
Choose a base branch
from
alejandro.gonzalez/APPSEC-56455
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9b82465
Fix org.json iast instrumentation test for latest dependency
jandro996 3757b32
fix codenarc
jandro996 9b54eec
add new instrumentation and cover more constructors
jandro996 58bba68
fix muzzle and check previous latest version
jandro996 4984a98
Merge branch 'master' into alejandro.gonzalez/APPSEC-56455
jandro996 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
84 changes: 84 additions & 0 deletions
84
...n/src/main/java/datadog/trace/instrumentation/json/JSONObject20241224Instrumentation.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,84 @@ | ||
package datadog.trace.instrumentation.json; | ||
|
||
import static datadog.trace.agent.tooling.bytebuddy.matcher.ClassLoaderMatchers.hasClassNamed; | ||
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor; | ||
import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
import static net.bytebuddy.matcher.ElementMatchers.isPublic; | ||
import static net.bytebuddy.matcher.ElementMatchers.returns; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments; | ||
|
||
import com.google.auto.service.AutoService; | ||
import datadog.trace.agent.tooling.Instrumenter; | ||
import datadog.trace.agent.tooling.InstrumenterModule; | ||
import datadog.trace.api.iast.InstrumentationBridge; | ||
import datadog.trace.api.iast.Propagation; | ||
import datadog.trace.api.iast.propagation.PropagationModule; | ||
import java.util.Map; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
@AutoService(InstrumenterModule.class) | ||
public class JSONObject20241224Instrumentation extends InstrumenterModule.Iast | ||
implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice { | ||
public JSONObject20241224Instrumentation() { | ||
super("org-json"); | ||
} | ||
|
||
static final ElementMatcher.Junction<ClassLoader> AFTER_20241224 = | ||
hasClassNamed("org.json.StringBuilderWriter"); | ||
|
||
@Override | ||
public String muzzleDirective() { | ||
return "after_20241224"; | ||
} | ||
|
||
@Override | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a muzzle reference rather than a class loader matcher? |
||
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() { | ||
return AFTER_20241224; | ||
} | ||
|
||
@Override | ||
public String instrumentedType() { | ||
return "org.json.JSONObject"; | ||
} | ||
|
||
@Override | ||
public void methodAdvice(MethodTransformer transformer) { | ||
// public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration) | ||
transformer.applyAdvice( | ||
isConstructor() | ||
.and(takesArguments(2)) | ||
.and(takesArgument(0, named("org.json.JSONTokener"))) | ||
.and(takesArgument(1, named("org.json.JSONParserConfiguration"))), | ||
getClass().getName() + "$ConstructorAdvice"); | ||
// private JSONObject(Map<?, ?> m, int recursionDepth, JSONParserConfiguration | ||
// jsonParserConfiguration) | ||
transformer.applyAdvice( | ||
isConstructor() | ||
.and(takesArguments(3)) | ||
.and(takesArgument(0, Map.class)) | ||
.and(takesArgument(1, int.class)) | ||
.and(takesArgument(2, named("org.json.JSONParserConfiguration"))), | ||
getClass().getName() + "$ConstructorAdvice"); | ||
transformer.applyAdvice( | ||
isMethod() | ||
.and(isPublic()) | ||
.and(returns(Object.class)) | ||
.and(named("opt")) | ||
.and(takesArguments(String.class)), | ||
packageName + ".OptAdvice"); | ||
} | ||
|
||
public static class ConstructorAdvice { | ||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
@Propagation | ||
public static void afterInit(@Advice.This Object self, @Advice.Argument(0) final Object input) { | ||
final PropagationModule iastModule = InstrumentationBridge.PROPAGATION; | ||
if (iastModule != null && input != null) { | ||
iastModule.taintObjectIfTainted(self, input); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't know if this is a problem, can they be named identically? perhaps it's beneficial to name it differently?