mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-09 19:45:13 +02:00
Dynamic (#77)
This commit is contained in:
parent
55247b7fcd
commit
991c84a1eb
1464 changed files with 225448 additions and 1985 deletions
28
tests/dynamic_fixtures/java/fileio_negative.java
Normal file
28
tests/dynamic_fixtures/java/fileio_negative.java
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// File I/O — negative fixture.
|
||||
// Safe: normalizes the path and checks it stays within the base directory, so
|
||||
// the traversal payload cannot escape `testfiles/` to reach the planted canary.
|
||||
// Entry: Entry.readFile(String) Cap: FILE_IO
|
||||
// Expected verdict: NotConfirmed
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
|
||||
public class Entry {
|
||||
public static void readFile(String userPath) throws Exception {
|
||||
// Same base the harness plants the canary one level above; the
|
||||
// containment check is what makes this safe.
|
||||
Path base = Paths.get(System.getProperty("user.dir"), "testfiles").toRealPath();
|
||||
Path resolved = base.resolve(userPath).normalize();
|
||||
if (!resolved.startsWith(base)) {
|
||||
System.out.println("Access denied");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
byte[] data = Files.readAllBytes(resolved);
|
||||
int len = Math.min(data.length, 100);
|
||||
System.out.write(data, 0, len);
|
||||
} catch (IOException e) {
|
||||
System.out.println("File not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue