Repository navigation
Refuse under AspectJ the method references and super calls its checks cannot see - #468
MarkusPaulsen wants to merge 5 commits into
Conversation
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.
|
Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
|
| Check name | Status | Explanation |
|---|---|---|
| Trusted Boundary Preservation | 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 | 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 fromJavaCreator.requireObservableUnderAspectJ, whichJavaTestCaseFactoryAndBuilder.executeTestCasescalls beforeexecuter.executeTestCases. It therefore runs before any test or student code runs. - The check reads onlyimportedSupervisedClasses, the classes read from the supervised class path. It skips every class inexemptedClassNames(JavaAspectJUnobservableAccessCheck.javalines 97–101). That set is built from the Ares essential classes and the instructor's test classes (JavaCreator.javalines 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 earlierrequireWovenSupervisedClassesstep 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 undersrc/test(for exampleFileSystemAccessReadTest,ThreadSystemAccessTestandJavaAspectJUnobservableAccessCheckTest) 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 basemainbranch also differs from the PR base, so I scoped the review to the PR commits. ThePackagePermissionchanges (removal ofexactMatchOnlyand 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, headfix/enforcement/ares-222-aspectj-unobservable-calls, basemain, author MarkusPaulsen) does not change any file under.github/workflows/. Evidence: - A three-dot diff againstorigin/main(merge base 563038b) lists only two files under.github/:.github/ISSUE_TEMPLATE/bug-report.ymland.github/scripts/CheckReleaseTemplate.java. Neither is a GitHub Actions workflow or action definition. - Filtering the same diff for.github/workflowsand action-file patterns returned no matches. -git statusshows 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, nopermissions, secret exposure orpull_request_targetcheckout pattern is introduced by this PR. The check is inapplicable. Limitation: the localorigin/mainref 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). InHierarchy.classPathSupertypes(lines 485–497), a class that cannot be found or read returnsSupertypes.NONE. This happens whenClassLoader.getSystemResourceAsStreamreturnsnull, or onIOException | RuntimeException.ownerAndSupertypesthen 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,refuseSuperCallsandrefuseInheritedImplementationsall depend on this lookup, so they return without aSecurityException. Concrete path: a student method reference toSub::start, whereSubextends an unreadable class that extendsThread, 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 aSecurityExceptionfor 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 whenimportedSupervisedClasses == null. The normal call order sets this field increateTestCasesbeforeexecuteTestCases. 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).instanceMethodsOfSupervisedInterfacereturns 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.JavaAspectJUnobservableAccessCheckTestcovers only the readable cases. Thecatch (SecurityException refusal)inJupiterIOExtensionrethrows 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 silentNONEfallback 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
- In
src/main/java/de/tum/cit/ase/ares/api/aop/java/aspectj/JavaAspectJUnobservableAccessCheck.java, changeHierarchy.classPathSupertypesso that a missing or unreadable class file throws aSecurityException. Use the existing message keysecurity.architecture.class.file.missing, ascallsOf(JavaClass)does. Do not returnSupertypes.NONEfor this case. RemoveSupertypes.NONEif no caller still needs it. 2. InJavaCreator.requireObservableUnderAspectJ, throw aSecurityExceptionwhenimportedSupervisedClassesisnulland either list is non-empty. Do not return silently. 3. Add tests toJavaAspectJUnobservableAccessCheckTest. 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.
- In
- 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.
Claudia-Anthropica
left a comment
There was a problem hiding this comment.
@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
left a comment
There was a problem hiding this comment.
@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
left a comment
There was a problem hiding this comment.
@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
left a comment
There was a problem hiding this comment.
@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.
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 throughsuperand a file name passed on throughsuper(...)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:
Files::readString,FileInputStream::new,Socket::neworworkers.forEach(Thread::start);super, such assuper.list()in a subclass ofFile;FileInputStreamthat passes a file name tosuper(...).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
superis 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
superand returns the result, asuper()without arguments of aReader,Writer, unconnectedSocketor exception, also with anewbeside it, a lambda inside aThreadsubclass and references to methods the student's own classes implement with code of their own. A class that lets an inherited checked method such asThread.startstand for a method of the student's own interface is refused before the tests run.3. Improvement from the maintainer's perspective
JavaAspectJUnobservableAccessCheckTestcovers each refused construct and its accepted counterpart: a lambda in aThreadsubclass, other overloads, overrides that hand on tosuperor change the call, asupercall to an inherited JDK method (super.parallelStream()in anArrayListsubclass),super()besidenew Socket(...), a student interface implemented by an inheritedThread.start, andsuper()of aFileHandleragainst an exception. The AspectJ modes gain static tests forThread::startand an archive subclass; the method-reference start has its own subject.aspectj-vs-instrumentation-weaknesses.mdandbaseline-verification.mdstill say AspectJ misses a thread started through a method reference, left for a follow-up.4. Testing manual
Prerequisites
JAVA_TOOL_OPTIONS='-Duser.language=en -Duser.country=GB'so the messages appear in English.mainand this branch once each and keep both JARs, from the repository root:git fetch origin, thengit switch --detach origin/main, thenmvn -q install -DskipTests -Pwithout-quality-gates, then copy the folder~/.m2/repository/de/tum/cit/ase/ares/2.2.2to a folderares-mainnext to the clone.git switch --detach origin/fix/enforcement/ares-222-aspectj-unobservable-calls, then the samemvncommand.~/.m2now holds the branch build as 2.2.2.ares-mainback over~/.m2/repository/de/tum/cit/ase/ares/2.2.2; to run it on the branch, run themvncommand of the branch again.examples/ares-exercise-gradle. You are the instructor:PenguinTest.javaandsrc/test/resources/SecurityPolicy.yamlare yours. The policy grades with ArchUnit and AspectJ and lets the student readallowed.txtand no other file.Penguin.javais what a student hands in. Createnotes.txtwith one line in the example folder; the policy has no entry for it.mavenLocal()as the first line insiderepositories { }inbuild.gradle.PenguinTest.java. It asserts that readingnotes.txtthe student's way is refused:./gradlew test(gradlew.bat teston Windows). The result of each test is on its own page: openbuild/reports/tests/test/index.htmland follow the links down to the test. After the last step, rungit checkout -- examplesandgit clean -fdx examples.Steps
notes.txtthrough a reference toFiles.readString. Add toPenguin.java:./gradlew test.Files::readStringbyp -> Files.readString(p). Run./gradlew test.Penguin.javaby a subclass that opensnotes.txtthroughsuper(...):./gradlew test.theFollowingProgrammingLanguageConfigurationIsUsedinSecurityPolicy.yamltoJAVA_USING_GRADLE_WALA_AND_ASPECTJand run./gradlew test.JAVA_USING_GRADLE_ARCHUNIT_AND_INSTRUMENTATIONand run./gradlew test.Expected result
readsTheUnlistedFileIndirectlyfails with "Expected java.lang.SecurityException to be thrown, but nothing was thrown", and the three example tests pass. The student readnotes.txt, which the policy does not list, and nobody is told. If it is refused, you are not on main.readsTheUnlistedFileIndirectlywould mean the reference still ran.notes.txtinside it is refused while it runs, which is whatreadsTheUnlistedFileIndirectlyasserts.readsTheUnlistedFileIndirectlyfails with "Expected java.lang.SecurityException to be thrown, but nothing was thrown": the subclass openednotes.txt.Files.readStringitself, so it refuses the read through the reference while the code runs and needs no new check. SettingJAVA_USING_GRADLE_WALA_AND_INSTRUMENTATIONgives the same result.Negative case (what must still be rejected)
rejectsTheForbiddenFilestill passes wherever the tests run, so a directFiles.readStringof a file the policy does not list is still refused.readsTheUnlistedFileIndirectlypasses. Change its path toallowed.txtand assert the content instead: the read is allowed, so the new check refuses nothing the policy permits.mvn test -Dtest=JavaAspectJUnobservableAccessCheckTestrefuses a reference, asupercall 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 aThread::startreference and an archive subclass under AspectJ.Modes exercised
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
JavaAspectJUnobservableAccessCheckJavaCreatorBreaking 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 onlyReader,Writer, an unconnectedSocketand 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
documentation/,README.md, Javadoc) was updated where the change is user-facing.Review progress