|
| 1 | +import java.sql.*; |
| 2 | +import java.net.*; |
| 3 | +import java.util.logging.*; |
| 4 | +import java.nio.charset.StandardCharsets; |
| 5 | +import testlib.TestSources; |
| 6 | + |
| 7 | +class Test { |
| 8 | + private TestSources sources = new TestSources(); |
| 9 | + |
| 10 | + private String byteToString(byte[] data) { |
| 11 | + return new String(data, StandardCharsets.UTF_8); |
| 12 | + } |
| 13 | + |
| 14 | + public void M1(Statement handle) throws Exception { |
| 15 | + // Only a source if "remote" is a selected threat model. |
| 16 | + // This is included in the "default" threat model. |
| 17 | + Socket sock = new Socket("localhost", 1234); |
| 18 | + byte[] data = new byte[1024]; |
| 19 | + sock.getInputStream().read(data); |
| 20 | + |
| 21 | + // Logging sink |
| 22 | + Logger.getLogger("foo").severe(byteToString(data)); |
| 23 | + |
| 24 | + // SQL sink |
| 25 | + handle.executeUpdate("INSERT INTO foo VALUES ('" + byteToString(data) + "')"); |
| 26 | + } |
| 27 | + |
| 28 | + public void M2(Statement handle) throws Exception { |
| 29 | + // Only a source if "database" is a selected threat model. |
| 30 | + String result = sources.executeQuery("SELECT * FROM foo"); |
| 31 | + |
| 32 | + // SQL sink |
| 33 | + handle.executeUpdate("INSERT INTO foo VALUES ('" + result + "')"); |
| 34 | + |
| 35 | + // Logging sink |
| 36 | + Logger.getLogger("foo").severe(result); |
| 37 | + } |
| 38 | + |
| 39 | + public void M3(Statement handle) throws Exception { |
| 40 | + // Only a source if "environment" is a selected threat model. |
| 41 | + String result = sources.readEnv("MY_ENV_VAR"); |
| 42 | + |
| 43 | + // SQL sink |
| 44 | + handle.executeUpdate("INSERT INTO foo VALUES ('" + result + "')"); |
| 45 | + |
| 46 | + // Logging sink |
| 47 | + Logger.getLogger("foo").severe(result); |
| 48 | + } |
| 49 | + |
| 50 | + public void M4(Statement handle) throws Exception { |
| 51 | + // Only a source if "custom" is a selected threat model. |
| 52 | + String result = sources.getCustom("custom"); |
| 53 | + |
| 54 | + // SQL sink |
| 55 | + handle.executeUpdate("INSERT INTO foo VALUES ('" + result + "')"); |
| 56 | + |
| 57 | + // Logging sink |
| 58 | + Logger.getLogger("foo").severe(result); |
| 59 | + } |
| 60 | + |
| 61 | + public void M5(Statement handle) throws Exception { |
| 62 | + // Only a source if "cli" is a selected threat model. |
| 63 | + byte[] data = new byte[1024]; |
| 64 | + System.in.read(data); |
| 65 | + |
| 66 | + // SQL sink |
| 67 | + handle.executeUpdate("INSERT INTO foo VALUES ('" + byteToString(data) + "')"); |
| 68 | + |
| 69 | + // Logging sink |
| 70 | + Logger.getLogger("foo").severe(byteToString(data)); |
| 71 | + } |
| 72 | +} |
0 commit comments