fix(aop): correct allowlist path matching for non-existing policy entries#97
fix(aop): correct allowlist path matching for non-existing policy entries#97SedaOran wants to merge 2 commits into
Conversation
…ries Both the Instrumentation and AspectJ file-system toolboxes had two related bugs in checkIfPathIsForbidden / pathMatches: 1. variableToPath was called with the operation's allowNonExistingPathsToBeConsidered flag when resolving *policy* entries. For read-operations (flag=false) this caused any policy entry whose file did not yet exist on disk to be silently dropped, making the entire allowlist unreachable. 2. pathMatches returned false (no match) whenever the allowed path from the policy did not exist, again irrespective of whether the candidate path matched it lexically. Fix: always pass true when resolving policy-entry paths (they must be compared even when the target file has not been created yet), and in pathMatches always compute the normalised absolute form of an non-existing allowed path instead of returning false. These bugs caused: allowed resources to be blocked (SecurityException on allowlisted files), and wrong-target policy tests to not throw SecurityException (any access to a non-existing file bypassed the allowlist check entirely). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR modifies filesystem security policy path matching to honor whitelist entries for non-existing paths. The changes ensure that policy-defined allowed paths are normalized and resolved upfront, then matched via absolute-form prefix checking, even when the referenced files don't exist yet. ChangesNon-Existing Path Whitelist Honoring
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
variableToPathwas called withallowNonExistingPathsToBeConsidered=falsewhen resolving policy entries. For read-operations this caused any allowlist rule whose file did not yet exist on disk to be silently skipped, making the entire allowlist unreachable.pathMatchesreturnedfalse(no match) whenever the allowed path from the policy did not exist, regardless of whether the candidate path matched lexically.JavaInstrumentationAdviceFileSystemToolbox(Byte Buddy mode) andJavaAspectJFileSystemAdviceDefinitions(AspectJ mode).Effect: Explicitly allowed resources were still blocked (SecurityException on allowlisted files), and wrong-target policy tests did not throw SecurityException because access to non-existing files bypassed the allowlist check entirely.
Related Issues
Fixes: Allowed Resource Access Fails (Issues #6, #7) and WrongTarget Policy Violation in AspectJ Modes (Issues #2, #3).
Test plan
protected/allowed.txtfor readsFiles.readString(Path.of("protected/allowed.txt"))— should PASSFiles.readString(Path.of("protected/other.txt"))— should throw SecurityExceptionWrongTargetPolicyMatrixTestin ARCHUNIT+ASPECTJ and WALA+ASPECTJ Gradle modes — allwrongTarget_*assertions should pass🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes