Skip to content

Refuse under AspectJ the method references and super calls its checks cannot see - #468

Open
MarkusPaulsen wants to merge 5 commits into
mainfrom
fix/enforcement/ares-222-aspectj-unobservable-calls
Open

MarkusPaulsen wants to merge 5 commits into
mainfrom
fix/enforcement/ares-222-aspectj-unobservable-calls

Conversation

@MarkusPaulsen

@MarkusPaulsen MarkusPaulsen commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Under AspectJ, Ares checks a call only where it finds it in the student's compiled code. A method or constructor reference such as Files::readString, a call through super and a file name passed on through super(...) were not checked against the policy while the code ran. Ares now refuses such code before any test runs and tells the student to call the method directly or inside a lambda.

Linked issues

Split from #461

1. Problem

Part of Ares at fault: checking a call against the policy while the code runs, with AspectJ (ArchUnit or WALA, Maven or Gradle). Instrumentation was not affected.

AspectJ weaves its check into each place where the student's code calls a checked method. Once a policy allows anything in an area, for example one readable file, the check before the tests leaves that area to this runtime check. Some ways of reaching a method leave no such place in the student's code:

  • a method or constructor reference, such as Files::readString, FileInputStream::new, Socket::new or workers.forEach(Thread::start);
  • a call through super, such as super.list() in a subclass of File;
  • a subclass of FileInputStream that passes a file name to super(...).

None of them was checked against the policy: a submission could read a file the policy does not list, or start more threads than it allows.

2. Improvement from the user's perspective

Instructors who grade with AspectJ get the checks their policy names: a read or thread start written as a method reference or reached through super is no longer left unchecked.

A student who uses one of these constructs is told before any test runs, in English or German, which class reaches which method and what to write instead: a direct call or a lambda. The ordinary forms stay accepted: lambdas, direct calls, an override that passes its parameters unchanged once to the same method through super and returns the result, a super() without arguments of a Reader, Writer, unconnected Socket or exception, also with a new beside it, a lambda inside a Thread subclass and references to methods the student's own classes implement with code of their own. A class that lets an inherited checked method such as Thread.start stand for a method of the student's own interface is refused before the tests run.

3. Improvement from the maintainer's perspective

JavaAspectJUnobservableAccessCheckTest covers each refused construct and its accepted counterpart: a lambda in a Thread subclass, other overloads, overrides that hand on to super or change the call, a super call to an inherited JDK method (super.parallelStream() in an ArrayList subclass), super() beside new Socket(...), a student interface implemented by an inherited Thread.start, and super() of a FileHandler against an exception. The AspectJ modes gain static tests for Thread::start and an archive subclass; the method-reference start has its own subject. aspectj-vs-instrumentation-weaknesses.md and baseline-verification.md still say AspectJ misses a thread started through a method reference, left for a follow-up.

4. Testing manual

Prerequisites

  1. JDK 17 and Maven 3.9 on the path, plus a clone of this repository in a folder without spaces. Run every command with JAVA_TOOL_OPTIONS='-Duser.language=en -Duser.country=GB' so the messages appear in English.
  2. Build main and this branch once each and keep both JARs, from the repository root:
    • git fetch origin, then git switch --detach origin/main, then mvn -q install -DskipTests -Pwithout-quality-gates, then copy the folder ~/.m2/repository/de/tum/cit/ase/ares/2.2.2 to a folder ares-main next to the clone.
    • git switch --detach origin/fix/enforcement/ares-222-aspectj-unobservable-calls, then the same mvn command. ~/.m2 now holds the branch build as 2.2.2.
    • To run a step "on main", copy ares-main back over ~/.m2/repository/de/tum/cit/ase/ares/2.2.2; to run it on the branch, run the mvn command of the branch again.
  3. Work in examples/ares-exercise-gradle. You are the instructor: PenguinTest.java and src/test/resources/SecurityPolicy.yaml are yours. The policy grades with ArchUnit and AspectJ and lets the student read allowed.txt and no other file. Penguin.java is what a student hands in. Create notes.txt with one line in the example folder; the policy has no entry for it.
  4. Gradle has to take Ares from the local Maven repository: add mavenLocal() as the first line inside repositories { } in build.gradle.
  5. Add this test to PenguinTest.java. It asserts that reading notes.txt the student's way is refused:
    @PublicTest
    void readsTheUnlistedFileIndirectly() {
        assertThrows(SecurityException.class, () -> new Penguin("Julian").readThroughReference());
    }
  6. Run the tests with ./gradlew test (gradlew.bat test on Windows). The result of each test is on its own page: open build/reports/tests/test/index.html and follow the links down to the test. After the last step, run git checkout -- examples and git clean -fdx examples.

Steps

  1. Method reference, on main. A student reads notes.txt through a reference to Files.readString. Add to Penguin.java:
    interface Io {
        String read(Path p) throws IOException;
    }
    
    public String readThroughReference() throws IOException {
        Io f = Files::readString;
        return f.read(Path.of("notes.txt"));
    }
    Run ./gradlew test.
  2. Repeat step 1 on the branch.
  3. Lambda, on the branch. The student follows the advice: replace Files::readString by p -> Files.readString(p). Run ./gradlew test.
  4. Super constructor, on main. Replace the code of step 1 in Penguin.java by a subclass that opens notes.txt through super(...):
    static final class NotesStream extends java.io.FileInputStream {
        NotesStream() throws IOException {
            super("notes.txt");
        }
    }
    
    public String readThroughReference() throws IOException {
        try (NotesStream s = new NotesStream()) {
            return new String(s.readAllBytes());
        }
    }
    Run ./gradlew test.
  5. Repeat step 4 on the branch.
  6. WALA, on the branch. Put the code of step 1 back, set theFollowingProgrammingLanguageConfigurationIsUsed in SecurityPolicy.yaml to JAVA_USING_GRADLE_WALA_AND_ASPECTJ and run ./gradlew test.
  7. Instrumentation, on the branch. With the code of step 1, set the configuration to JAVA_USING_GRADLE_ARCHUNIT_AND_INSTRUMENTATION and run ./gradlew test.

Expected result

  1. readsTheUnlistedFileIndirectly fails with "Expected java.lang.SecurityException to be thrown, but nothing was thrown", and the three example tests pass. The student read notes.txt, which the policy does not list, and nobody is told. If it is refused, you are not on main.
  2. All four tests fail before they run, each with "org.example.Penguin refers to java.nio.file.Files.readString(java.nio.file.Path) through a method or constructor reference, which Ares cannot check while the code runs under AspectJ. Call it directly or inside a lambda instead." The student is told what to change; no test result can be earned while the read through the reference is in the submission. A passing readsTheUnlistedFileIndirectly would mean the reference still ran.
  3. All four tests pass. The lambda is woven like any other call, so the read of notes.txt inside it is refused while it runs, which is what readsTheUnlistedFileIndirectly asserts.
  4. As in step 1, readsTheUnlistedFileIndirectly fails with "Expected java.lang.SecurityException to be thrown, but nothing was thrown": the subclass opened notes.txt.
  5. All four tests fail before they run with "org.example.Penguin$NotesStream reaches the constructor java.io.FileInputStream.(java.lang.String) through super(...), which Ares cannot check while the code runs under AspectJ. Create the object with new instead of extending its class."
  6. All four tests fail with the message of step 2: the check does not depend on the architecture engine.
  7. All four tests pass, as they do on main: instrumentation checks Files.readString itself, so it refuses the read through the reference while the code runs and needs no new check. Setting JAVA_USING_GRADLE_WALA_AND_INSTRUMENTATION gives the same result.

Negative case (what must still be rejected)

  1. Branch, every step: the example's own test rejectsTheForbiddenFile still passes wherever the tests run, so a direct Files.readString of a file the policy does not list is still refused.
  2. Branch, step 3: the lambda is refused while it runs, so readsTheUnlistedFileIndirectly passes. Change its path to allowed.txt and assert the content instead: the read is allowed, so the new check refuses nothing the policy permits.
  3. In this repository, mvn test -Dtest=JavaAspectJUnobservableAccessCheckTest refuses a reference, a super call and a super constructor that reach a checked method, and accepts their counterparts. mvn test -Dtest='ArchiveEntryInterceptionTest,de.tum.cit.ase.ares.integration.architecture.forbidden.ThreadSystemAccessTest#*MethodReference*_test,de.tum.cit.ase.ares.integration.architecture.forbidden.FileSystemAccessReadTest#*archiveSubclass*_test' runs the archive subclass under instrumentation, where it is refused while it runs, and the refusals before the tests of a Thread::start reference and an archive subclass under AspectJ.

Modes exercised

  • ArchUnit + AspectJ
  • ArchUnit + instrumentation
  • WALA + AspectJ
  • WALA + instrumentation

The new check runs only under AspectJ, with either architecture engine: steps 2, 3, 5 and 6 show it with ArchUnit and WALA. Step 7 shows both instrumentation modes unchanged.

5. Test case coverage regarding this PR

Class Instruction coverage Branch coverage Line coverage Complexity coverage Method coverage Confirmation (meaningful assertions)
JavaAspectJUnobservableAccessCheck pending CI pending CI pending CI pending CI pending CI yes
JavaCreator pending CI pending CI pending CI pending CI pending CI yes

Breaking changes and migration

Under AspectJ, a submission that reaches a checked method through a method or constructor reference, a call through super, a super constructor (without arguments only Reader, Writer, an unconnected Socket and exceptions are accepted), or an inherited checked method standing for a method of its own interface is now refused before the tests run, where before it ran without a check against the policy. Precompile gets this check once #467 is merged too. Nothing changes for instructors: no policy or build file needs editing. Students write a direct call or a lambda instead, as the message tells them.

Checklist

  • The title of this pull request describes the change, not the implementation.
  • I followed the guidelines for inclusive, diversity-sensitive and appreciative language.
  • I have self-reviewed the diff of this pull request.
  • Tests were added or updated for the behaviour changed here.
  • Javadoc follows the AGENTS.md conventions.
  • Documentation (documentation/, README.md, Javadoc) was updated where the change is user-facing.
  • CI is green, or every remaining failure is explained above.
  • No secrets, tokens or absolute local paths are contained in the diff.

Review progress

  • Code review
  • Manual test

Markus Paulsen added 2 commits November 26, 2026 01:30
AspectJ checks a call only where it finds it in the student's compiled
code. Once a policy granted anything in an area, so that only the runtime
check decided it, a method or constructor reference such as
Files::readString or FileInputStream::new, a call through super such as
super.list() in a File subclass, or a FileInputStream subclass passing a
file name to super(...) ran unchecked; the same held for Socket::new and
for workers.forEach(Thread::start) beyond the allowed number of threads.
Instrumentation was not affected.

In an AspectJ run Ares now refuses, before any test runs, such a
reference or super call to a method of an area the runtime decides alone,
for both architecture engines. A call through super from an override of
the same method stays allowed, since AspectJ sees every call of the
override, and so does a super constructor without arguments. Threads are
exempt from the super-constructor rule, as AspectJ sees new Worker().
The message tells the student to call the method directly or in a lambda.

The record whose thread start through a method reference only
instrumentation could refuse gets its own subject, so the direct start
keeps its runtime tests, and the AspectJ modes gain static tests for that
reference and for an archive subclass, which replace the archive's
runtime tests in AspectJ.
…s declare

ArchUnit lists a lambda as a reference to the method holding its body, so
the AspectJ check refused every lambda in a Thread subclass, the class
named java.lang.Thread being reached on the way up. The search through the
hierarchy now stops at a supervised class that declares the method with
the same parameter types, since that code is woven and checked; an
overload of another signature does not stop it.
@MarkusPaulsen
MarkusPaulsen requested a review from a team November 26, 2026 00:59
@MarkusPaulsen
MarkusPaulsen requested review from a team and krusche as code owners November 26, 2026 00:59
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

Failed Failed checks: 1 error

Check name Status Explanation Resolution
Sandbox Fail-Closed Behaviour Error The PR adds a new enforcement class, JavaAspectJUnobservableAccessCheck.java (764 lines, new in this PR). Its type-hierarchy lookup does not fail closed for partially resolved input. Evidence: 1. Fa… 1. In src/main/java/de/tum/cit/ase/ares/api/aop/java/aspectj/JavaAspectJUnobservableAccessCheck.java, change Hierarchy.classPathSupertypes so that a missing or unreadable class file throws a SecurityException. Use the existing message…
Passed Passed checks: 2 passed

Check name Status Explanation
Trusted Boundary Preservation Passed The PR keeps the separation between trusted Ares code, test fixtures and supervised (student) code. Evidence (PR-specific range 75b2bfb..HEAD, which is the five PR commits; the local checkout also co…
Github Workflow Least Privilege Passed The check applies only when a pull request changes GitHub workflow files. This pull request (ls1intum/Ares2 #468, head fix/enforcement/ares-222-aspectj-unobservable-calls, base main, author Markus…
Full details: Trusted Boundary Preservation

Explanation

The PR keeps the separation between trusted Ares code, test fixtures and supervised (student) code. Evidence (PR-specific range 75b2bfb..HEAD, which is the five PR commits; the local checkout also contains earlier commits that are not part of this PR): - The new check, JavaAspectJUnobservableAccessCheck.requireObservable, runs inside trusted Ares code. It is called from JavaCreator.requireObservableUnderAspectJ, which JavaTestCaseFactoryAndBuilder.executeTestCases calls before executer.executeTestCases. It therefore runs before any test or student code runs. - The check reads only importedSupervisedClasses, the classes read from the supervised class path. It skips every class in exemptedClassNames (JavaAspectJUnobservableAccessCheck.java lines 97–101). That set is built from the Ares essential classes and the instructor's test classes (JavaCreator.java lines 762–766). The exemption boundary is therefore reused, not weakened. - The check does not change how the policy is read, how essential or exempted classes are defined, or how the AspectJ weaving check works. The earlier requireWovenSupervisedClasses step is unchanged. - The new refusal messages use the existing "Reason: Student-Code" convention. They identify the student class and the reached method, and they do not expose trusted internals beyond the existing message style. - Test fixtures added under src/test (for example FileSystemAccessReadTest, ThreadSystemAccessTest and JavaAspectJUnobservableAccessCheckTest) stay in the test tree. Several of the new archive-subclass probes are @Disabled. None of the new fixtures change production classes or the trusted/supervised split. Limits: I did not run the tests, because build tools are unavailable in this sandbox. The verdict rests on source inspection. The base main branch also differs from the PR base, so I scoped the review to the PR commits. The PackagePermission changes (removal of exactMatchOnly and the JDK-namespace flag) appear in commit 75b2bfb, which is outside this PR. I did not count them against this PR.

Full details: Github Workflow Least Privilege

Explanation

The check applies only when a pull request changes GitHub workflow files. This pull request (ls1intum/Ares2 #468, head fix/enforcement/ares-222-aspectj-unobservable-calls, base main, author MarkusPaulsen) does not change any file under .github/workflows/. Evidence: - A three-dot diff against origin/main (merge base 563038b) lists only two files under .github/: .github/ISSUE_TEMPLATE/bug-report.yml and .github/scripts/CheckReleaseTemplate.java. Neither is a GitHub Actions workflow or action definition. - Filtering the same diff for .github/workflows and action-file patterns returned no matches. - git status shows no uncommitted changes under .github. - The PR changes are Java AspectJ enforcement code, tests, policy fixtures, documentation and example build files. The PR description does not mention workflow or permission changes. Because no workflow changes exist, no permissions, secret exposure or pull_request_target checkout pattern is introduced by this PR. The check is inapplicable. Limitation: the local origin/main ref may not match the PR's base exactly. The diff still shows no changed workflow file, so this does not change the result.

Full details: Sandbox Fail-Closed Behaviour

Explanation

The PR adds a new enforcement class, JavaAspectJUnobservableAccessCheck.java (764 lines, new in this PR). Its type-hierarchy lookup does not fail closed for partially resolved input. Evidence: 1. Fail-open fallback (main finding). In Hierarchy.classPathSupertypes (lines 485–497), a class that cannot be found or read returns Supertypes.NONE. This happens when ClassLoader.getSystemResourceAsStream returns null, or on IOException | RuntimeException. ownerAndSupertypes then stops at that type and never visits its superclass or interfaces. firstListed (lines 232–248) therefore finds no listed method inherited above that type. refuseReferences, refuseSuperCalls and refuseInheritedImplementations all depend on this lookup, so they return without a SecurityException. Concrete path: a student method reference to Sub::start, where Sub extends an unreadable class that extends Thread, passes the check. Under AspectJ, that call is not woven and runs unchecked. 2. Inconsistent fail-closed handling in the same class. callsOf(JavaClass) (lines 302–315) throws a SecurityException for a missing or unreadable supervised class file. The hierarchy read does not follow that pattern. The PR therefore refuses one partial-input case and silently accepts the other. 3. Silent skip on a null state. JavaCreator.requireObservableUnderAspectJ (lines 359–361) returns without a check when importedSupervisedClasses == null. The normal call order sets this field in createTestCases before executeTestCases. The skip is therefore reachable only on an out-of-order call. It is a lesser concern, but it is still an unknown state that passes. 4. Narrow design gap (not the basis of this verdict). instanceMethodsOfSupervisedInterface returns no methods for interfaces outside the supervised set. A JDK interface that declares a listed signature is therefore not examined. The PR states this scope on purpose. I found no test for an unreadable or absent hierarchy class. JavaAspectJUnobservableAccessCheckTest covers only the readable cases. The catch (SecurityException refusal) in JupiterIOExtension rethrows the refusal, so it does not weaken the check. Reachability of item 1 depends on the class loader that resolves library and JDK class files. In typical Gradle or Maven runs, the JDK classes resolve. The criterion asks whether the code keeps fail-closed behaviour for partially resolved inputs. The silent NONE fallback does not. The previous standing FAIL has no details. I checked the current state, and the defect is still present, so the prior failure is not addressed.

Resolution

  1. In src/main/java/de/tum/cit/ase/ares/api/aop/java/aspectj/JavaAspectJUnobservableAccessCheck.java, change Hierarchy.classPathSupertypes so that a missing or unreadable class file throws a SecurityException. Use the existing message key security.architecture.class.file.missing, as callsOf(JavaClass) does. Do not return Supertypes.NONE for this case. Remove Supertypes.NONE if no caller still needs it. 2. In JavaCreator.requireObservableUnderAspectJ, throw a SecurityException when importedSupervisedClasses is null and either list is non-empty. Do not return silently. 3. Add tests to JavaAspectJUnobservableAccessCheckTest. One test should cover a method reference to an inherited listed method, where the superclass cannot be read. The test should assert a refusal. A second test should cover the null-classes state. 4. Re-run the AspectJ check tests and confirm that the refusals hold.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions github-actions Bot added aop Automated area label: aop architecture Automated area label: architecture tests Automated area label: tests securitytest Automated area label: securitytest labels Nov 26, 2026

@Claudia-Anthropica Claudia-Anthropica left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@MarkusPaulsen I found three gaps in the AspectJ protection and a constructor scan that rejects permitted direct calls. Please address the inline findings before merging. Several CI jobs, including Unit Tests and the WALA enforcement jobs, were still running in the captured results; no required checks were listed.

A reference to a student override that only hands on to the checked
method through super ran both calls unchecked, since the reference
stopped at the student's declaration and the hand-on was exempt. Such
an override no longer ends the search up the hierarchy.

A call through super that names a JDK class inheriting the checked
method, as javac writes super.parallelStream() in an ArrayList subclass,
was matched against that class alone. The search now reads the
superclasses and interfaces of every class, JDK classes from their
class files without loading them.

A constructor calling super() and creating an object of its superclass
with new was refused, because every superclass constructor call was
counted once one was not matched by a new. Each constructor call is now
paired with the latest object created with new, so only the call on the
object being built counts.

@Claudia-Anthropica Claudia-Anthropica left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@MarkusPaulsen Thanks for fixing the earlier direct-reference, hierarchy and constructor cases. I found two additional AspectJ bypasses that I missed in the previous review, detailed inline. Unit Tests, enforcement jobs and several other CI checks were still unfinished in the captured results; no required checks were listed.

…e reach

AspectJ checks a call by the type the calling code names. A class that
lets a listed method it inherits, such as Thread.start, stand for a
method of a student interface could therefore be called through that
interface, or referenced through it, without that check. Ares now
refuses such a class before the tests run, also when the class only
hands the method on to super. An abstract declaration no longer counts
as code of the student's own when the hierarchy is searched.

An override counted as handing on whenever it called the method it
overrides through super. It now counts only when its whole body passes
its parameters unchanged to that method once and returns the result.
Any other call to the overridden method through super, with another
argument or more than once, is refused like any other call through
super.

@Claudia-Anthropica Claudia-Anthropica left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@MarkusPaulsen Thanks, the latest fixes address the reported interface-dispatch and altered-forwarding cases. I missed two constructor gaps in the earlier reviews: the no-argument exemption permits unchecked file creation, and excluding thread constructors leaves Timer subclasses unchecked. Both are detailed inline. Build, the example jobs and Java analysis were still running; no required checks were listed.

Ares accepted every super() call without arguments, on the ground that
such a constructor opens nothing it could be told to open. The
FileHandler constructor without arguments opens the configured log
file, and the check of the outer new sees no path to judge. Only the
listed constructors without arguments that open nothing are now
accepted: Reader, Writer, an unconnected Socket and exceptions. Every
other listed one is refused through super() as well.

@Claudia-Anthropica Claudia-Anthropica left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@MarkusPaulsen Thanks, FileHandler super() is now refused while the inert constructors remain accepted. The Timer issue also affects direct construction in the unchanged runtime advice, which supports handling it separately. After reviewing the full diff, this looks good to me for the Postcompile scope. Build, example jobs and CodeQL were still running; no required checks were listed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aop Automated area label: aop architecture Automated area label: architecture securitytest Automated area label: securitytest tests Automated area label: tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants