Skip to content

Java: Enable BarrierGuard wrappers #20183

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

Merged
merged 6 commits into from
Aug 14, 2025

Conversation

aschackmull
Copy link
Contributor

This enables the Guards library wrapper guard integration with BarrierGuard such that data flow sanitizers make use of the full power of the Guards library including wrapped validation checks.

Some individual barriers had ad-hoc support for this, which can now be deleted as it becomes superfluous.

@aschackmull aschackmull requested a review from a team as a code owner August 7, 2025 13:47
@Copilot Copilot AI review requested due to automatic review settings August 7, 2025 13:47
@github-actions github-actions bot added the Java label Aug 7, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables the Guards library wrapper guard integration with BarrierGuard in Java, allowing data flow sanitizers to leverage the full power of the Guards library including wrapped validation checks. This eliminates the need for ad-hoc support in individual barriers.

  • Adds support for SSA definition-based guard checking in the Guards library
  • Refactors BarrierGuard implementation to use wrapped validation checks with state
  • Removes custom validation method logic from path sanitizers and arithmetic guards

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
shared/controlflow/codeql/controlflow/Guards.qll Adds guardChecksDef predicate for SSA definition validation and removes deprecated boolean guard logic
java/ql/lib/semmle/code/java/security/PathSanitizer.qll Removes ValidationMethod module and simplifies sanitizer classes to use only BarrierGuard
java/ql/lib/semmle/code/java/security/ArithmeticCommon.qll Refactors size guard predicates to work with expressions and updates guard checking to use BarrierGuard
java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll Updates BarrierGuard implementation to use wrapped validation with SSA definitions
java/ql/lib/semmle/code/java/controlflow/Guards.qll Removes deprecated implies_v3 predicate

@aschackmull
Copy link
Contributor Author

Fixed the kotlin qltest in two ways (either of the two added commits suffice to fix the test). Firstly, kotlin Throws annotations are now recognized - we definitely want that, as that's similar to the java throws clauses. Second, I've extended the cfg heuristic for adding exception edges, since guard wrappers may make use of unchecked exceptions, so if we see a call chain reaching something that may act as a guard wrapper then we add exception edges. Lets see if the latter in particular shows any effects in dca.

@aschackmull aschackmull force-pushed the java/barrierguard-wrappers branch from 1acee9d to 492a5ca Compare August 8, 2025 08:40
private predicate methodMayThrow(Method m, ThrowableType t) {
exists(AstNode n |
t = n.(ThrowStmt).getThrownExceptionType() and
not n.(ThrowStmt).getParent() = any(Method m0).getBody()
Copy link
Contributor

@hvitved hvitved Aug 14, 2025

Choose a reason for hiding this comment

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

Is this to filter out methods that always throw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

@@ -210,7 +178,6 @@ predicate overflowSink(ArithExpr exp, VarAccess use) {
exp instanceof PostIncExpr or
exp instanceof MulExpr
) and
not guardedLessThanSomething(use) and
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this removed (and the line below)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's part of the barrier, so it's superfluous to filter like this in the sink definition.

@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Aug 14, 2025
@aschackmull aschackmull merged commit b67394a into github:main Aug 14, 2025
43 of 44 checks passed
@aschackmull aschackmull deleted the java/barrierguard-wrappers branch August 14, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Java no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants