Skip to content

Check each file by what the code does to it, and read text as text - #470

Open
MarkusPaulsen wants to merge 20 commits into
mainfrom
fix/enforcement/ares-222-file-system-roles
Open

MarkusPaulsen wants to merge 20 commits into
mainfrom
fix/enforcement/ares-222-file-system-roles

Conversation

@MarkusPaulsen

@MarkusPaulsen MarkusPaulsen commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Ares now decides each file access by what the code does to each file, the same way in both runtime modes. Correct code was refused: reading text with Scanner or StringReader, writing a new file under a policy that allows creating files, console stream wrappers, thread getters and plain logging. Process redirects, links, provider streams, moves and channel transfers were decided by another permission than the one the policy names.

Linked issues

Split from #461

1. Problem

Correct submissions failed, in all four modes unless named:

  • new Scanner("4 5") and new StringReader("a\nb") were refused as reads of a file called like the text.
  • A policy allowing only createAllFiles refused Files.writeString to a new file as an overwrite.
  • Without file allowances, the static check (ArchUnit or WALA, before the code runs) refused wrappers over System.in, Properties.load from text, Thread.currentThread() and Logger.getLogger.
  • ArchUnit with instrumentation could refuse every test once a class of a second package loaded.

Other accesses were not decided by the permission the policy names for them:

  • AspectJ: ProcessBuilder.redirectOutput(file) was not checked against the file entry of the policy.
  • All modes: ProcessBuilder.environment() was not treated like System.getenv; provider links and streams, SecureDirectoryStream, the read side of Files.move and RandomAccessFile, and channel transfers were checked by another flag or not at all.

2. Improvement from the user's perspective

Correct student code that Ares refused before now passes: text scanning, console stream wrappers, plain logging, thread getters, and writes the policy allows by one flag. An instructor's file entry now means the same for every way of using a file: createAllFiles for a new file, overwriteAllFiles for an existing one, read permission for every read. A process redirect needs the file permission for the file it names, and ProcessBuilder.environment() gets the same answer as System.getenv. Under ReflectionTestUtils, an Ares refusal now reaches the test unchanged.

3. Improvement from the maintainer's perspective

New tests cover what nothing covered: Scanner and reader text, write flags per writer, the role of each file in moves, copies, links, transfers and redirects, provider streams, secure directory streams, wrappers and getters under the static rules, and ReflectionTestUtils passing a refusal on. Both runtime backends now derive the open mode of a file the way the JDK does, with one shared rule instead of per-method special cases, so AspectJ and instrumentation agree on each case. The contributor pages describe that rule as it now works.

4. Testing manual

Prerequisites

  1. JDK 17 and Maven 3.9 on the path, macOS or Linux (step 2 runs the program echo), and a clone of this repository in a folder without spaces.
  2. Build main and this branch once each and keep both JARs, from the repository root:
    • git switch main then mvn -q install -DskipTests -Pwithout-quality-gates, then copy ~/.m2/repository/de/tum/cit/ase/ares/2.2.2 to a folder ares-main next to the clone.
    • git switch fix/enforcement/ares-222-file-system-roles 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 install command of the branch again.
  3. Work in examples/ares-exercise-maven. You are the instructor: PenguinTest.java and src/test/resources/SecurityPolicy.yaml are yours, Penguin.java is what a student hands in. Run git checkout -- examples and git clean -fdx examples after each step. The change is build-tool independent; the Gradle example behaves the same.

Steps

  1. Text and a new file, all modes. Add to Penguin.java:
    public static int sum(String s) { java.util.Scanner sc = new java.util.Scanner(s); return sc.nextInt() + sc.nextInt(); }
    public static String first(String s) throws IOException { return new java.io.BufferedReader(new java.io.StringReader(s)).readLine(); }
    public static void writeNew() throws IOException { Files.writeString(Path.of("new.txt"), "hello"); }
    Add to PenguinTest.java:
    @PublicTest void scansText() { assertEquals(9, Penguin.sum("4 5")); }
    @PublicTest void readsText() throws Exception { assertEquals("a", Penguin.first("a\nb")); }
    @PublicTest void writesANewFile() throws Exception { java.nio.file.Files.deleteIfExists(java.nio.file.Path.of("new.txt")); Penguin.writeNew(); }
    In SecurityPolicy.yaml, add a second entry under regardingFileSystemInteractions with onThisPathAndAllPathsBelow: "new.txt", createAllFiles: true and the other four flags false. Run mvn test once per value of theFollowingProgrammingLanguageConfigurationIsUsed: JAVA_USING_MAVEN_ARCHUNIT_AND_ASPECTJ, JAVA_USING_MAVEN_ARCHUNIT_AND_INSTRUMENTATION, JAVA_USING_MAVEN_WALA_AND_ASPECTJ, JAVA_USING_MAVEN_WALA_AND_INSTRUMENTATION. Do it on main, then on the branch.
  2. Redirect, AspectJ. Keep the policy of step 1 and add an allowed command and the thread the JDK starts for it:
        regardingCommandExecutions:
          - executeTheCommand: "echo"
            withTheseArguments: [ "hello" ]
        regardingThreadCreations:
          - createTheFollowingNumberOfThreads: 100
            ofThisClass: "java.lang.ProcessHandleImpl$1"
    Create notes.txt with one line in the example folder; the policy has no entry for it. Add public static void redirect() throws Exception { new ProcessBuilder("echo", "hello").redirectOutput(new java.io.File("notes.txt")).start().waitFor(); } to Penguin.java and @PublicTest void refusesARedirectToAnUnlistedFile() { assertThrows(SecurityException.class, Penguin::redirect); } to PenguinTest.java. Run mvn test with JAVA_USING_MAVEN_ARCHUNIT_AND_ASPECTJ on main, then open notes.txt. Repeat on the branch.
  3. Environment, ArchUnit and WALA. Starting from a clean example, add only the regardingCommandExecutions entry of step 2, public static int env() { return new ProcessBuilder().environment().size(); } to Penguin.java and @PublicTest void readsTheEnvironment() { assertTrue(Penguin.env() > 0); } to PenguinTest.java. Run mvn test with JAVA_USING_MAVEN_ARCHUNIT_AND_ASPECTJ on main, then on the branch with it and with JAVA_USING_MAVEN_WALA_AND_ASPECTJ.

Expected result

  1. On main scansText, readsText and writesANewFile fail in all four modes, with "tried to illegally read the file /4 5 via java.util.Scanner.(java.lang.String)", the same for a and b via java.io.StringReader.<init>, and "tried to illegally overwrite the file /new.txt via java.nio.file.Files.writeString", although new.txt did not exist. On the branch all six tests pass in all four modes and new.txt holds hello.
  2. On main refusesARedirectToAnUnlistedFile fails with "Expected java.lang.SecurityException to be thrown, but nothing was thrown", and notes.txt now holds hello: the redirect was not checked against the file entries. On the branch the test passes and notes.txt keeps its line. With instrumentation, main already refused this on macOS and Linux.
  3. On main the test passes: environment() was not checked like System.getenv. On the branch every test fails, in both engines, with "org.example.Penguin.env() tried to illegally access the environment via java.lang.ProcessBuilder.environment()", the refusal System.getenv gets.

Negative case (what must still be rejected)

  1. Branch, any step above: the example's own test rejectsTheForbiddenFile still passes in every mode, so a read of a file the policy does not list is still refused.
  2. Branch, step 1: add @PublicTest void refusesOverwritingAnExistingFile() throws Exception { java.nio.file.Files.writeString(java.nio.file.Path.of("new.txt"), "old"); assertThrows(SecurityException.class, Penguin::writeNew); }. It passes in all four modes: createAllFiles alone does not let the code replace an existing file.
  3. Branch, step 2: add static String scanNotes() throws Exception { return new java.util.Scanner(java.nio.file.Path.of("notes.txt")).nextLine(); } and the same with new java.io.File("notes.txt"), each tested with assertThrows(SecurityException.class, ...). Both pass in all four modes: a Scanner on a file is still checked as a read of that file.
  4. In this repository, mvn test -Dtest='FileOpeningRolesTest,FileWriteFlagsTest,ResourceReadTest,FileSystemAccessReadTest,FileSystemAccessOverwriteTest,StaticRuleNarrowingTest,CommandSystemAccessTest' runs, in all four modes, the refusals and permissions for write flags, the role of each file in moves, copies, links, transfers and redirects, provider streams, secure directory streams, class-path resources, and the static narrowing of wrappers, getters and logging. FileOpeningRolesTest also refuses a transfer into or out of a channel the test class opened on an existing file under createAllFiles only, after a failed opening, into a replaced file and through a link to a missing file, and allows a transfer into a new file the code opened itself. mvn test -Dtest=ReflectionTestUtilsSecurityExceptionTest shows a refusal reaching the test unchanged.

Modes exercised

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

Steps 1 and 2 were run together in all four modes on main and on the branch (only AspectJ leaves the redirect unchecked on main), and negative case 2 with them; step 3 in ArchUnit and WALA with AspectJ, since the static check decides it. A class of a second package under ArchUnit with instrumentation did not fail on main from either example on this machine, so that fix has no step here. The Windows redirect check runs only on the Windows CI jobs. Under instrumentation a write through an open file channel is checked at its opening and in transfers, not on each write. Reading an allowed class-path resource under instrumentation also needs the network fix split from #461, which stops the network check from refusing the file: URL the JDK opens; until then ResourceReadTest covers the allowed read with AspectJ only.

5. Test case coverage regarding this PR

Class Instruction coverage Branch coverage Line coverage Complexity coverage Method coverage Confirmation (meaningful assertions)
JavaInstrumentationAdviceFileSystemToolbox pending CI pending CI pending CI pending CI pending CI yes
JavaInstrumentationAdviceAbstractToolbox pending CI pending CI pending CI pending CI pending CI yes
JavaInstrumentationPointcutDefinitions pending CI pending CI pending CI pending CI pending CI yes
ReflectionTestUtils pending CI pending CI pending CI pending CI pending CI yes

Breaking changes and migration

  • Writing RandomAccessFiles on existing files, Files.move and Files.newInputStream also need read permission.
  • Writing needs createAllFiles for a new file and overwriteAllFiles for an existing one, for every way of writing.
  • A class-path resource is checked as a read of its copy in the build output, such as target/classes/data.txt.
  • ProcessBuilder.environment() is refused like System.getenv, and a process redirect needs the file permission for the file it names.
  • A write through a file that is already open, such as FileChannel.write or a transfer, needs overwriteAllFiles; createAllFiles is enough only through the handle that a checked opening of the code returned when it created the file. Writing through a link to a missing file is refused; REPLACE_EXISTING onto a link replaces the link and needs overwriteAllFiles there.

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 15 commits November 26, 2026 01:30
The first time a student class of another package loads during a test,
Byte Buddy reads class files through the class loader, which opens the
AspectJ runtime JAR on the boot class path. The file check blamed that
read on the student frames below it, the transformation failed, and the
agent stopped enforcement, failing every test in ArchUnit with
instrumentation, for Maven and Gradle.

The file check now skips such a read, as the network check already did.
Both now require every frame between the checked call and the Byte Buddy
transformer to be the JDK, Byte Buddy or the Ares agent on the system
class loader, so a class loader or URL handler of the supervised code
keeps the call checked.
Both runtime checks took the String argument of new Scanner(String) and
new StringReader(String) for a file name and refused a read of a file
called like the text, in all four modes, although neither opens a file.

AspectJ now intercepts only the Scanner constructors that take a File or
a Path and ignores the charset name next to it. Instrumentation reads no
argument of either constructor as a path; a Scanner on a file is checked
where it opens the stream underneath.

New tests scan and read text and read the permitted file with a charset
name, and refuse Scanner(File), Scanner(File, String) and Scanner(Path)
on the forbidden file, which no test covered before.
Under AspectJ, an allowed command could write its output into any file,
append to one or read its input from a forbidden one through the
ProcessBuilder redirects, since the JDK opens those files itself; Ares now
checks redirectInput, redirectOutput, redirectError and the Redirect
factories as reads and writes, as instrumentation already did.
ProcessBuilder.environment() handed supervised code every environment
variable, which System.getenv is refused for, and is now refused the same
way in both architecture engines.

The network policy page says how host names, addresses and listening are
matched.
…here they lie

Whether writing a file needed createAllFiles or overwriteAllFiles
depended on the API. FileWriter, PrintWriter, FileOutputStream and
Files.newBufferedWriter fired both a create and an overwrite pointcut,
so an existing file needed both flags and the refusal said "overwrite"
while the create check had failed. RandomAccessFile "rw",
FileChannel.open with CREATE and, under AspectJ, Files.writeString and
Files.write were checked as overwrites only, so an overwrite-only policy
let them create new files. A create-only policy refused every writer
that put content into the new file.

Both runtime backends now derive the open mode the way the JDK does:
the write methods add WRITE (or CREATE, TRUNCATE_EXISTING, WRITE when
given no option), a channel without a write option opens for reading,
and a write without CREATE_NEW or CREATE needs the file to exist. An
opening for writing becomes one check at the moment it is made: an
overwrite when the named file exists, a create when it does not. Files.copy
with REPLACE_EXISTING follows the same rule for its destination. A write
through a file that is already open (FileChannel, RandomAccessFile) is
allowed where either flag covers the file, since its opening was
checked. DELETE_ON_CLOSE now adds its delete check instead of replacing
the others, and RandomAccessFile.writeBytes/writeChars/writeUTF no
longer read their text as a path.

Class.getResourceAsStream and ClassLoader.getResourceAsStream are
checked as a read of the file the resource is found in (or its JAR),
not of the resource name taken as a path relative to the working
directory. AspectJ now intercepts Class.getResourceAsStream as well.
…tic rules

Under a policy without file allowances the static rules refused
System.in.read(), new BufferedInputStream(System.in), a BufferedWriter
over System.out, Properties.load(Reader) and, with WALA, reads from
byte or char arrays, because the file method lists named the wrappers
InputStream.read, Reader, Writer, Buffered* and Properties.load/store.
None of them opens a file: the constructor or method that does is
listed on its own, so the wrapper entries are removed from both lists.
The provider methods newInputStream, newOutputStream, newByteChannel,
newFileChannel and newAsynchronousFileChannel are added, since they open
a file without any other listed call.

The thread list carried a class-level java.lang.Thread entry, so
Thread.currentThread(), getName() or isInterrupted() were refused under
a policy without thread allowances. The entry is narrowed to what starts,
stops, waits for or reconfigures a thread, with the builders and the
Arrays.parallel* operations listed explicitly; the getters stay allowed.

System.setOut/setErr/setIn were reported as reflection (ArchUnit) or
class loading (WALA). They stay refused, since they replace the
streams of the whole JVM, but now as environment access.
Logger.getLogger(String) was refused as reflection; a named logger is
harmless and is allowed, while Logger.addHandler, which lets code run
whenever anything in the JVM logs, is refused as environment access.
Class.getResourceAsStream moves from the reflection list to the file
list and Class.getClassLoader leaves the WALA class-loading list, so a
class-path resource is decided by the file permission.

With fewer sinks, the WALA run over the ancestor-package fixture now
reports a different Ares test class first, one whose method takes an
argument; the fixture test accepted only methods without arguments, so
its pattern now accepts any parameter list.
ReflectionTestUtils.newInstance and invokeMethod turned every exception
of the called code into an AssertionFailedError with a generic text, so
an Ares SecurityException read "check your constructor" and
assertThrows(SecurityException.class, ...) failed. A SecurityException
is now passed on unchanged; other exceptions are still reported as
failures.
The file system reference explains that writing needs createAllFiles
for a new file and overwriteAllFiles for an existing one, whatever API
is used, that a class-path resource is read from the build output, and
that wrappers over memory need no entry. The thread reference explains
that thread getters are allowed. What Ares does not protect against now
says that file metadata (Files.exists, size, timestamps) is not checked.
The contributor pages follow the new method lists and action derivation.
Java 25 builds a StringReader on Reader.of(CharSequence), whose class is
a nested class of java.io.Reader, so instrumentation again took the text
of Scanner(String) and StringReader(String) for a file name. No argument
of the constructor of such a JDK nested reader is now read as a path.
… each file

Four file operations were checked against the wrong permission, or not
at all, in both runtime backends.

A file system provider opens files directly:
path.getFileSystem().provider().newInputStream(path), newOutputStream,
newByteChannel, newFileChannel and newAsynchronousFileChannel. AspectJ
did not intercept any of them, and the instrumentation backend did not
either, so any file permission let code read and write every file this
way. Both backends now intercept them and decide them like the Files
methods: by their options, writing by whether the file exists. A
provider method counts as one of FileSystemProvider whichever provider
class runs it. Files.newInputStream and the provider's newInputStream
always read, so an option such as DELETE_ON_CLOSE no longer replaces the
read check. Under instrumentation the provider is also the inner step of
Files.createTempFile, which the temp-file exemption now accepts.

RandomAccessFile in mode "rw", "rws" or "rwd" was checked as a write
only, although such a file can be read as well. It now also needs the
read permission.

Files.move never checked its source for reading, so a policy granting
overwrite and delete but not read let code move a secret file into a
folder it could read. It also checked both paths for overwrite and
delete. Files.move and FileSystemProvider.move now check each side: the
source for read and delete, the target for create when it is missing
and for overwrite when it exists. FileSystemProvider.copy now follows
the Files.copy rule, so under instrumentation the provider step inside
Files.copy no longer checks the source as an overwrite.

PrintWriter(String|File, String charset) and Formatter(String|File,
String charset) read the charset name as a path and refused a correct
submission. Only the file argument is checked now. A constructor
without arguments, such as new Formatter() inside String.format, names
no path and is not filtered.

FileOpeningRolesTest checks each case allowed and refused in all four
modes. The RandomAccessFile writer leaves FileWriteFlagsTest, whose
policies grant no read, and is covered by the new test instead.
A review of the file rework found five gaps.

RandomAccessFile in a write mode needed read even for a file that does
not exist yet, so under instrumentation ImageIO.write to a new file was
refused by a policy granting create, overwrite and delete without read.
Opening a file for reading and writing now needs read only when the file
exists. ImageIO.createImageOutputStream(File) and new
FileImageOutputStream(File) open their file the same way; AspectJ now
checks them so too, where it checked the first as a plain overwrite and
did not intercept the second.

FileSystemProvider.createLink, createSymbolicLink and deleteIfExists
were intercepted by neither backend nor listed for the static rules. They
now follow Files.createLink, Files.createSymbolicLink and
Files.deleteIfExists. SecureDirectoryStream.newByteChannel,
newDirectoryStream and move, reachable on macOS as well as on Linux,
were not intercepted either. A secure directory stream reads a relative
path against its own folder, which Ares cannot see, so both backends now
refuse a relative path given to it unless the action is allowed for
every path, and check an absolute one like any other. Its move has the
roles of Files.move. The static lists named SecureDirectoryStream.deleteFile
and deleteDirectory with a Path parameter, which never matches the
erased call, so they now name Object.

FileChannel.transferTo was always refused under AspectJ, because its
write firing reached the unknown-action branch. Under instrumentation the
JDK's FileChannelImpl was excluded from instrumentation altogether, so
neither transfer was checked and a socket on the other side never went
through the network check. FileChannelImpl is now watched for its two
transfers only. Both backends recognise the channel by its type and check
each side: transferTo needs read on its file, write on a file target and
send to a network target; transferFrom needs write on its file, read on
a file source and receive from a network source. The instrumentation
probe now names the class the agent really reports.

The Javadoc of the copy, move and transfer check and the contributor page
describe the firings as they now work.
On Linux the provider opens a new temp file through its newFileChannel,
which the temp-file exemption did not name, so Files.createTempFile was
refused under instrumentation for a policy without file rules.
On Windows a process redirect bypassed the file permissions under
instrumentation. ProcessBuilder.redirectOutput(Redirect.appendTo(file))
let an allowed command append to a file the policy does not allow,
because the JDK's Windows ProcessImpl opens a redirect file natively when
the process starts, and on Linux and macOS only the FileOutputStream it
opens there was checked. AspectJ checked the redirect where the student
names the file. Instrumentation now does the same:
ProcessBuilder.redirectOutput, redirectError, Redirect.to and
Redirect.appendTo are checked as a write, a create for a missing file and
an overwrite for an existing one, in both backends, and redirectInput and
Redirect.from as a read. Only the File argument is read as a path; the
command strings held by the builder are not, which before refused every
redirect of a builder under AspectJ. On Linux and macOS the stream the
JDK opens when the process starts is checked by the same rule, so both
checks agree.
Naming a file for a process redirect writes or reads that file, but the
static method lists did not name the redirect methods. A policy without
any file rule therefore never refused a redirect before the run. Both
lists now name ProcessBuilder.redirectInput, redirectOutput and
redirectError and Redirect.from, to and appendTo with a File. The tests
that expected the refusal at run time without any file rule are now
static probes.
@MarkusPaulsen
MarkusPaulsen requested a review from a team November 26, 2026 01:03
@MarkusPaulsen
MarkusPaulsen requested review from a team and krusche as code owners November 26, 2026 01:03
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

Pre-merge checks: Passed 3

Check name Status Explanation
Sandbox Fail-Closed Behaviour Passed Summary: the enforcement changes in PR #470 (ls1intum/Ares2, author MarkusPaulsen, base main, head fix/enforcement/ares-222-file-system-roles) keep fail-closed behaviour for the unknown, malformed, nu…
Trusted Boundary Preservation Passed Summary: The changes keep the separation between trusted Ares infrastructure, test fixtures and supervised code. Most changes tighten it. I found three residual points for follow-up. None of them …
Github Workflow Least Privilege Passed The check is not applicable to this pull request. PR #470 (ls1intum/Ares2, head fix/enforcement/ares-222-file-system-roles, base main) changes no GitHub Actions workflow file. Evidence: - I compared t…
Full details: Sandbox Fail-Closed Behaviour

Explanation

Summary: the enforcement changes in PR #470 (ls1intum/Ares2, author MarkusPaulsen, base main, head fix/enforcement/ares-222-file-system-roles) keep fail-closed behaviour for the unknown, malformed, null and partially resolved inputs I checked. I found no changed-code path that turns such an input into an allow. I did not run tests or build the project. The evidence comes from reading the diff and current code. Evidence of preserved or stronger fail-closed behaviour: - Unknown actions throw. The AspectJ and instrumentation advices throw a SecurityException for an unknown action in the move, transfer and allowance switches (for example the default branches at the checkMoveRole and checkCheckSinglePath-style switches, and the unknown.action messages in both toolboxes). - Unknown RandomAccessFile modes fall back to the pointcut's own action (getRandomAccessFileModeActions returns null, then deriveActionChecks uses defaultAction). They do not fall through to allow. - Path checks deny on an unresolved existing path. In checkIfPathIsForbidden, a failing toRealPath() now returns true (denied) unless the check acts on the link itself and the path is a symbolic link. The base code allowed a normalised-path fallback when allowNonExistingPathsToBeConsidered was true. - Null or empty allow-lists deny. A null or empty allow-list returns true (violation). - A failed opening grants nothing. rememberCreatedHandle(null, true) runs in an after-throwing advice on the same pointcut set. A write through a handle needs the create allowance only when a checked creation returned that exact handle. A handle the test class opened needs the overwrite rule. - Policy input is validated strictly. SecurityPolicySchemaValidator rejects unknown fields and null or wrongly typed values. FAIL_ON_UNKNOWN_PROPERTIES is enabled in SecurityPolicyYAMLReader. The removed exactMatchOnly field is now refused as an unknown field, and SecurityPolicyStrictSchemaTest.rejectsAnExactMatchOnlyField covers it. A policy that still uses it fails to load rather than widening access. - The WALA classifier fails closed. WalaPathClassification.hasInfrastructureOrigin throws unclassifiableNode for a missing node, method, class or class-loader identity, and for any unexpected runtime error. Residual points for reviewers. None of these establishes a PR-introduced fail-open path: 1. resourceReadTargets returns an empty target list when getResource returns null or the protocol is jrt. The call is then not checked as a path. This is a new explicit allow for unresolved resources. No file is opened when the lookup returns null, so I did not find a bypass. A targeted test for a resource that the lookup cannot resolve would confirm it. 2. resolveWriteAction returns create when no argument resolves to a path. The same unresolved argument is also not checked in analyseViolation, so this default does not add a new allow path. It is pre-existing in kind. 3. variableToPath returns null for an InvalidPathException and for unrecognised types, so those arguments are not checked. The base code has the same pattern. 4. resolveExistingAncestorRealPath falls back to the unresolved input path on IOException. The PR now also uses it in linkLocation for link-itself checks. This extends the reach of an existing fallback, so it merits a closer look. 5. CustomCallgraphBuilder skips a dependency whose normalised class name is null. This occurs only for primitive arrays and malformed descriptors. Scope note. I read the AspectJ file-system advice in detail. For the instrumentation toolbox I confirmed the same functions, the same default and throw branches, and the same checkIfPathIsForbidden fallback. I did not read every instrumentation method line by line.

Full details: Trusted Boundary Preservation

Explanation

Summary: The changes keep the separation between trusted Ares infrastructure, test fixtures and supervised code. Most changes tighten it. I found three residual points for follow-up. None of them lets supervised code reach or reclassify trusted code. I compared the merge base 563038b with the head 9d5439b. The PR is by MarkusPaulsen, and the head branch is fix/enforcement/ares-222-file-system-roles. Changes that strengthen separation - Byte Buddy exemption narrowed. isByteBuddyTransformationInProgress (JavaInstrumentationAdviceAbstractToolbox, around lines 758–795) used to exempt any call with an ExecutingTransformer frame on the stack. It now needs every frame between the call and the transformer to be a JDK class or a Byte Buddy or Ares agent class from the system class loader. A student class loader or URL handler in between keeps the call checked. - Test-helper packages no longer treated as infrastructure. In WalaPathClassification, INFRA_PREFIXES no longer contains anonymous.toolclasses. or metatest.. These prefixes were previously skipped when attributing violations, and the old comments say supervised code could be named into them. Student code in those packages is now analysed as supervised code. RESERVED_PACKAGE_PREFIXES is unchanged. - Wider checks on supervised code. The PR adds coverage for sun.nio.ch.FileChannelImpl, ProcessBuilder redirects and environment(), SecureDirectoryStream, FileSystemProvider operations, and provider streams. These checks apply to supervised code, not to Ares code. - Namespace reservation kept. The ArchUnit and WALA reserved-namespace checks remain. The PR only changes one message string in JavaArchunitSupervisedClasses. Residual points (non-blocking) 1. Read exemptions extended to receiver and attribute checks. isSystemJarReadExempt and isExemptSystemFileAccess now also apply to the receiver and attribute checks in JavaInstrumentationAdviceFileSystemToolbox (around lines 2153–2198). They cover reads under java.home and the Maven repository only. The parameter path already had these exemptions before this PR. Ares policies and fixtures do not live in those trees. 2. Inconsistent prefix in the transitive check. TRANSITIVE_FALSE_POSITIVE_PREFIXES still uses the broad de.tum.cit.ase.ares. prefix. That prefix covers de.tum.cit.ase.ares.integration subjects, which the new INFRA comment says must stay supervised. This is pre-existing. Because the nearest student frame is chosen from the sink side, the practical effect appears limited. The prefix should still be aligned with the comment. 3. Error types changed for Ares-Code errors. ReportingUtils.processThrowable and TestGuardUtils now throw SecurityException for Ares-internal and test-setup faults. Previously these were AssertionError or AnnotationFormatError. The messages still carry the Reason: Ares-Code markers, so attribution text is preserved. The exception type, however, now matches the type used for student violations. A follow-up review of consumers that filter on this type is advisable. Limits: This assessment uses static diff and source inspection only. I did not build or run the tests.

Full details: Github Workflow Least Privilege

Explanation

The check is not applicable to this pull request. PR #470 (ls1intum/Ares2, head fix/enforcement/ares-222-file-system-roles, base main) changes no GitHub Actions workflow file. Evidence: - I compared the merge base with HEAD. The diff lists no file under .github/workflows/. The workflows at HEAD (actionlint, codeql, deploy-documentation, documentation-ci, documentation, examples, issue-labeler, maven, pullrequest-labeler, pullrequest-template, release-template) are unchanged. - Two files under .github/ are modified: .github/ISSUE_TEMPLATE/bug-report.yml (an issue form, not a workflow) and .github/scripts/CheckReleaseTemplate.java (a helper script). Neither defines a workflow, a permissions block, a secret reference, or a pull_request_target trigger. Neither is a workflow change in the sense the check uses. - The remaining changes concern Java sources, policy templates, tests, examples and documentation. None of these defines GitHub Actions configuration. Because no workflow change exists, the check's three conditions (minimal permissions, no secret exposure to untrusted PR code, no unsafe pull_request_target checkout) cannot be violated by this PR. The existing workflows are outside the scope of this PR.

  • 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 policy Automated area label: policy docs Automated area label: docs tests Automated area label: tests 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 one permission bypass: create-only permission now allows overwriting existing files through writable handles supplied by trusted test code. Please restrict that exemption to handles whose creation Ares actually authorised. Core Integration Tests, Enforcement Integration Tests (WALA + instrumentation), Windows Unit Tests, Windows Core Integration Tests, and Windows Enforcement Integration Tests (WALA + instrumentation) are still running.

…e code created it

A write through a file that is already open, such as FileChannel.write,
transferFrom or the target of transferTo, was accepted wherever the
overwrite or the create rule covered the file, because its opening was
checked. A channel the test class opened on an existing file was never
checked as an opening, so under a create-only rule the supervised code
could replace that file's content through it.

Both runtime backends now remember each file that a checked and allowed
opening of the supervised code created. For a write through an open file
they accept the create rule only for those files; every other file needs
the overwrite rule. New tests refuse transferFrom, transferTo and, under
AspectJ, FileChannel.write into an existing create-only file through a
channel the test class opened, and allow transferFrom into a new file the
code opened itself.

The redirect tests that build a ProcessBuilder for cat now use its full
path from the search path and are skipped where there is none.

@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 The new regression covers the originally reported supplied-handle case, but creation tracking still grants overwrite access after failed opens and across policy resets. I also confirmed a dangling-symlink escape that I missed earlier. Enforcement Integration Tests (WALA + instrumentation) failed with only exit code 1 and no test report, so I couldn't attribute that failure; eight other checks are still running.

…e the code opened

The create rule for a write through a file that is already open was
granted by pathname, recorded when the opening was checked. The record
outlived the policy that allowed it, and it was written even when the
opening then failed, for example new PrintWriter(file, charset) with an
unknown charset. A later handle on the same pathname, opened by the test
class, then got the create allowance.

Both runtime backends now note the new file when they allow an opening
that creates it, and remember the handle the opening returns once it has
succeeded: instrumentation in exit advice on the read, create and
overwrite advice, AspectJ in after returning advice. A failed opening
only drops the note. Handles are held weakly and forgotten when another
policy is armed or the settings are reset. Only a remembered handle, or
the channel of a remembered stream, gets the create rule for a write
through it; any other handle needs the overwrite rule.

A path that exists but cannot be resolved, such as a link to a missing
file, is now refused for every action. Before, a write through such a
link was checked at the link's own location while the JDK created the
file the link points to.

New tests cover a failed opening, a created file replaced at the same
pathname, a policy armed again and a write through a link to a missing
file, and keep a plain new file through FileOutputStream allowed.

@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 The earlier reported cases are fixed. I found two new issues: handle tracking can execute student code while enforcement is suppressed, and the link-resolution change blocks permitted deletion of dangling links. Build, Analyse Java, the documentation build and four example jobs are still running.

…link where it lies

Looking up a handle in the record of created handles called its hashCode.
The target of a transfer can be a channel the supervised code wrote, so
that lookup ran the code's own hashCode while the check was in progress.
Both backends now put and look up only objects of classes the boot loader
defined, whose hashCode and equals are the JDK's own.

Refusing a path that exists but cannot be resolved also refused deleting a
link to a missing file, although a deletion removes the link and nothing
else. A deletion is now checked at the link's own place, in both backends;
opening a file through such a link stays refused.

New tests transfer to a channel of the supervised code and check that its
hashCode was not called, and delete a link to a missing file in a folder
the policy lets the code delete in.

@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 The latest fixes address the handle-hashing and dangling-link deletion cases. I found a link-replacement regression that I missed earlier, plus an overstatement in the new permission documentation. Build, CodeQL, Analyse Java, Analyse Actions, the documentation build and four example jobs remain queued or running.

Files.copy and Files.move with REPLACE_EXISTING onto a link to a missing
file were refused, because the destination could not be resolved. The
JDK replaces the link itself and does not follow it. Both backends now
treat such a destination as an existing file, needing the overwrite rule,
and check it at the link's own place. Opening a file through such a link
stays refused.

The file system reference and the contributor page state that with
instrumentation a write or truncate through an open channel is checked
where the channel is opened and in transfers, not at each call.

New tests replace a link to a missing file by copy and by move in a
folder with the overwrite rule, and refuse both in a read-only folder.

@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 The reported dangling-link replacement cases and instrumentation documentation are fixed. I found an AspectJ overwrite bypass that I missed in the earlier review. Build, both CodeQL analyses, the documentation build and all four example jobs are still running.

…ter its check

Under AspectJ the check of Files.writeString runs at the call site of the
supervised code, and the JDK then turns the code's text into a string
before it opens the file. That text could put a link to an existing file
where the new file was to go, and the opening then followed the link.

Where the policy lets the code create a missing file but not overwrite
it, AspectJ now adds CREATE_NEW to the options of the opening before the
check, for the Files, channel and provider methods that take open
options. The JDK then refuses a file that is there by the time it opens,
and Ares reports that as an overwrite refusal. Instrumentation checks
inside the JDK right before the opening and refuses the same call already.

New tests write text that puts such a link in place and refuse it in all
four modes, and keep a plain new file through Files.writeString allowed.

@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 The new CREATE_NEW advice fixes the reported link-swap case, and I found no further issues in the current diff. Looks good to me. Unit, core and enforcement test jobs, the Windows Gradle example and Analyse Java are still running.

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 docs Automated area label: docs policy Automated area label: policy tests Automated area label: tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants