-
Notifications
You must be signed in to change notification settings - Fork 1
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
Java Debugger Interface implementation for analyzing security related method calls at Runtime #17
base: main
Are you sure you want to change the base?
Conversation
…ity violations in runtime
WalkthroughThe recent changes introduce the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant JDIStackTraceMonitor
participant JVM
User->>JDIStackTraceMonitor: Start monitoring
JDIStackTraceMonitor->>JVM: Attach to target JVM
JVM->>JDIStackTraceMonitor: Connection established
JDIStackTraceMonitor->>JVM: Set up method entry request
JVM->>JDIStackTraceMonitor: Method entry event occurs
JDIStackTraceMonitor->>User: Notify method entry
JDIStackTraceMonitor->>JVM: Handle security exceptions if needed
JDIStackTraceMonitor->>JVM: Monitor JVM termination
JVM->>JDIStackTraceMonitor: Termination event
JDIStackTraceMonitor->>User: Monitoring stopped
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 9
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- src/main/java/de/tum/cit/ase/ares/api/jdi/JDIStackTraceMonitor.java (1 hunks)
- src/main/java/de/tum/cit/ase/ares/api/jdi/StudentExample.java (1 hunks)
src/main/java/de/tum/cit/ase/ares/api/jdi/JDIStackTraceMonitor.java
Outdated
Show resolved
Hide resolved
EventQueue queue = vm.eventQueue(); | ||
while (true) { | ||
EventSet eventSet = queue.remove(); | ||
EventIterator eventIterator = eventSet.eventIterator(); | ||
while (eventIterator.hasNext()) { | ||
Event event = eventIterator.nextEvent(); | ||
if (event instanceof MethodEntryEvent methodEntryEvent) { | ||
List<String> locations = methodEntryEvent.thread().frames().stream().map(frame -> frame.location().toString()) | ||
.filter(location -> location.contains("StudentExample")) | ||
.toList(); | ||
if (!locations.isEmpty()) { | ||
throw new SecurityException("Access to sun.nio.fs.UnixFileSystemProvider is not allowed" + locations); | ||
} | ||
} else if (event instanceof VMDeathEvent || event instanceof VMDisconnectEvent) { | ||
return; | ||
} | ||
} | ||
eventSet.resume(); | ||
} |
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.
Improve readability and performance of event handling loop.
The current implementation can be improved for readability and performance.
- while (true) {
- EventSet eventSet = queue.remove();
- EventIterator eventIterator = eventSet.eventIterator();
- while (eventIterator.hasNext()) {
- Event event = eventIterator.nextEvent();
- if (event instanceof MethodEntryEvent methodEntryEvent) {
- List<String> locations = methodEntryEvent.thread().frames().stream().map(frame -> frame.location().toString())
- .filter(location -> location.contains("StudentExample"))
- .toList();
- if (!locations.isEmpty()) {
- throw new SecurityException("Access to sun.nio.fs.UnixFileSystemProvider is not allowed" + locations);
- }
- } else if (event instanceof VMDeathEvent || event instanceof VMDisconnectEvent) {
- return;
- }
- }
- eventSet.resume();
- }
+ boolean running = true;
+ while (running) {
+ EventSet eventSet = queue.remove();
+ for (Event event : eventSet) {
+ if (event instanceof MethodEntryEvent methodEntryEvent) {
+ List<String> locations = methodEntryEvent.thread().frames().stream()
+ .map(frame -> frame.location().toString())
+ .filter(location -> location.contains("StudentExample"))
+ .toList();
+ if (!locations.isEmpty()) {
+ throw new SecurityException(String.format("Access to sun.nio.fs.UnixFileSystemProvider is not allowed. Locations: %s", String.join(", ", locations)));
+ }
+ } else if (event instanceof VMDeathEvent || event instanceof VMDisconnectEvent) {
+ running = false;
+ break;
+ }
+ }
+ eventSet.resume();
+ }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
EventQueue queue = vm.eventQueue(); | |
while (true) { | |
EventSet eventSet = queue.remove(); | |
EventIterator eventIterator = eventSet.eventIterator(); | |
while (eventIterator.hasNext()) { | |
Event event = eventIterator.nextEvent(); | |
if (event instanceof MethodEntryEvent methodEntryEvent) { | |
List<String> locations = methodEntryEvent.thread().frames().stream().map(frame -> frame.location().toString()) | |
.filter(location -> location.contains("StudentExample")) | |
.toList(); | |
if (!locations.isEmpty()) { | |
throw new SecurityException("Access to sun.nio.fs.UnixFileSystemProvider is not allowed" + locations); | |
} | |
} else if (event instanceof VMDeathEvent || event instanceof VMDisconnectEvent) { | |
return; | |
} | |
} | |
eventSet.resume(); | |
} | |
EventQueue queue = vm.eventQueue(); | |
boolean running = true; | |
while (running) { | |
EventSet eventSet = queue.remove(); | |
for (Event event : eventSet) { | |
if (event instanceof MethodEntryEvent methodEntryEvent) { | |
List<String> locations = methodEntryEvent.thread().frames().stream() | |
.map(frame -> frame.location().toString()) | |
.filter(location -> location.contains("StudentExample")) | |
.toList(); | |
if (!locations.isEmpty()) { | |
throw new SecurityException(String.format("Access to sun.nio.fs.UnixFileSystemProvider is not allowed. Locations: %s", String.join(", ", locations))); | |
} | |
} else if (event instanceof VMDeathEvent || event instanceof VMDisconnectEvent) { | |
running = false; | |
break; | |
} | |
} | |
eventSet.resume(); | |
} |
….java Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/main/java/de/tum/cit/ase/ares/api/jdi/JDIStackTraceMonitor.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/main/java/de/tum/cit/ase/ares/api/jdi/JDIStackTraceMonitor.java
TBD....
Summary by CodeRabbit
New Features
JDIStackTraceMonitor
class for real-time monitoring of Java Debug Interface events, focusing on method entry tracking.StudentExample
class to demonstrate basic file reading functionality in Java.Bug Fixes