fix(example): stop POST / argument names from forging log entriesUnverified
Anyone can POST / over HTTP, and the argument names were logged raw: a name holding a line break wrote a second Cockpit entry, such as a fake "Command app:greet said: ..." line, which the example README presents as the proof that a Command Invocation ran. The names are now JSON-encoded, which escapes line breaks; checked on Scaleway before and after. The CRON Invocations measurement also named v0.1.0, while the deployed lock pins dev-main at 2bca487, which lacks the v0.1.0 Emulator fix only.
f65cec5 parent: b64f0a3 modified
docs/probe-results.md +2 -2 | @@ -83,13 +83,13 @@ Headers sent by the client: | ||
| 83 | 83 | |
| 84 | 84 | ## CRON Invocations |
| 85 | 85 | |
| 86 | -Measured on 2026-11-14 with the [example](../example) and `jdecool/scaleway-runtime` v0.1.0 (`php85`), its two triggers set to every minute in a copy of its Terraform, with two more: the `app:greet` arguments with a wrong secret, and with `--fail`. | |
| 86 | +Measured on 2026-11-14 on `php85` with the [example](../example), whose lock pins `jdecool/scaleway-runtime` at `dev-main` 2bca487 (v0.1.0 but for an Emulator fix), its two triggers set to every minute in a copy of its Terraform, with two more: the `app:greet` arguments with a wrong secret, and with `--fail`. | |
| 87 | 87 | For three minutes, each of the four triggers fired once a minute, 1 to 15 seconds past it, each Invocation preceded by `DEBUG - Function Triggered: / source=core`. |
| 88 | 88 | Their stderr lines, without the `DEBUG - ` prefix and ` source=user stream=stderr` suffix: |
| 89 | 89 | |
| 90 | 90 | | Trigger arguments | Logged | |
| 91 | 91 | | --- | --- | |
| 92 | -| `{"job": "hourly"}` | `[info] Matched route "app_demo_cron".`, then `[info] CRON Invocation received with the arguments job` | | |
| 92 | +| `{"job": "hourly"}` | `[info] Matched route "app_demo_cron".`, then `[info] CRON Invocation received with the arguments ["job"]` | | |
| 93 | 93 | | `app:greet`, `{"name": "CRON"}`, the right secret | `[info] Command app:greet said: Hello CRON!` only: no route matched, no failure | |
| 94 | 94 | | `app:greet`, a wrong secret | `Command Invocation rejected: the "secret" does not match SCALEWAY_CRON_SECRET, the body goes to the Application as a plain HTTP body.`, then the `POST /` lines | |
| 95 | 95 | | `app:greet`, `{"--fail": true}`, the right secret | `[info] Command app:greet said: Hello world!`, then `Command "app:greet" failed with exit code 1: Hello world!` and one entry per line of the output, blank ones included | |
| @@ -83,13 +83,13 @@ Headers sent by the client: | |||
| 83 | 83 | ||
| 84 | ## CRON Invocations | 84 | ## CRON Invocations |
| 85 | 85 | ||
| 86 | -Measured on 2026-11-14 with the [example](../example) and `jdecool/scaleway-runtime` v0.1.0 (`php85`), its two triggers set to every minute in a copy of its Terraform, with two more: the `app:greet` arguments with a wrong secret, and with `--fail`. | 86 | +Measured on 2026-11-14 on `php85` with the [example](../example), whose lock pins `jdecool/scaleway-runtime` at `dev-main` 2bca487 (v0.1.0 but for an Emulator fix), its two triggers set to every minute in a copy of its Terraform, with two more: the `app:greet` arguments with a wrong secret, and with `--fail`. |
| 87 | For three minutes, each of the four triggers fired once a minute, 1 to 15 seconds past it, each Invocation preceded by `DEBUG - Function Triggered: / source=core`. | 87 | For three minutes, each of the four triggers fired once a minute, 1 to 15 seconds past it, each Invocation preceded by `DEBUG - Function Triggered: / source=core`. |
| 88 | Their stderr lines, without the `DEBUG - ` prefix and ` source=user stream=stderr` suffix: | 88 | Their stderr lines, without the `DEBUG - ` prefix and ` source=user stream=stderr` suffix: |
| 89 | 89 | ||
| 90 | | Trigger arguments | Logged | | 90 | | Trigger arguments | Logged | |
| 91 | | --- | --- | | 91 | | --- | --- | |
| 92 | -| `{"job": "hourly"}` | `[info] Matched route "app_demo_cron".`, then `[info] CRON Invocation received with the arguments job` | | 92 | +| `{"job": "hourly"}` | `[info] Matched route "app_demo_cron".`, then `[info] CRON Invocation received with the arguments ["job"]` | |
| 93 | | `app:greet`, `{"name": "CRON"}`, the right secret | `[info] Command app:greet said: Hello CRON!` only: no route matched, no failure | | 93 | | `app:greet`, `{"name": "CRON"}`, the right secret | `[info] Command app:greet said: Hello CRON!` only: no route matched, no failure | |
| 94 | | `app:greet`, a wrong secret | `Command Invocation rejected: the "secret" does not match SCALEWAY_CRON_SECRET, the body goes to the Application as a plain HTTP body.`, then the `POST /` lines | | 94 | | `app:greet`, a wrong secret | `Command Invocation rejected: the "secret" does not match SCALEWAY_CRON_SECRET, the body goes to the Application as a plain HTTP body.`, then the `POST /` lines | |
| 95 | | `app:greet`, `{"--fail": true}`, the right secret | `[info] Command app:greet said: Hello world!`, then `Command "app:greet" failed with exit code 1: Hello world!` and one entry per line of the output, blank ones included | | 95 | | `app:greet`, `{"--fail": true}`, the right secret | `[info] Command app:greet said: Hello world!`, then `Command "app:greet" failed with exit code 1: Hello world!` and one entry per line of the output, blank ones included | |
modified
example/README.md +1 -1 | @@ -85,6 +85,6 @@ Against a deployment, `e2e/run.sh` skips the CRON scenarios, as only the platfor | ||
| 85 | 85 | Check them in the [logs](../README.md#logs) instead, after the triggers ran (at minutes 0 and 30): each one leaves its line, the second showing that `app:greet` ran as a Command Invocation. |
| 86 | 86 | |
| 87 | 87 | ``` |
| 88 | -DEBUG - [info] CRON Invocation received with the arguments job source=user stream=stderr | |
| 88 | +DEBUG - [info] CRON Invocation received with the arguments ["job"] source=user stream=stderr | |
| 89 | 89 | DEBUG - [info] Command app:greet said: Hello CRON! source=user stream=stderr |
| 90 | 90 | ``` |
| @@ -85,6 +85,6 @@ Against a deployment, `e2e/run.sh` skips the CRON scenarios, as only the platfor | |||
| 85 | Check them in the [logs](../README.md#logs) instead, after the triggers ran (at minutes 0 and 30): each one leaves its line, the second showing that `app:greet` ran as a Command Invocation. | 85 | Check them in the [logs](../README.md#logs) instead, after the triggers ran (at minutes 0 and 30): each one leaves its line, the second showing that `app:greet` ran as a Command Invocation. |
| 86 | 86 | ||
| 87 | ``` | 87 | ``` |
| 88 | -DEBUG - [info] CRON Invocation received with the arguments job source=user stream=stderr | 88 | +DEBUG - [info] CRON Invocation received with the arguments ["job"] source=user stream=stderr |
| 89 | DEBUG - [info] Command app:greet said: Hello CRON! source=user stream=stderr | 89 | DEBUG - [info] Command app:greet said: Hello CRON! source=user stream=stderr |
| 90 | ``` | 90 | ``` |
modified
example/src/Controller/DemoController.php +2 -1 | @@ -28,7 +28,8 @@ final class DemoController | ||
| 28 | 28 | { |
| 29 | 29 | $args = json_decode($request->getContent(), true); |
| 30 | 30 | // A body meant as a Command Invocation but rejected lands here: its secret must not reach the logs. |
| 31 | - $logger->info('CRON Invocation received with the arguments {keys}', ['keys' => implode(',', array_keys(\is_array($args) ? $args : []))]); | |
| 31 | + // Anyone can POST here: JSON-encoding the names escapes the line breaks that would forge log entries. | |
| 32 | + $logger->info('CRON Invocation received with the arguments {keys}', ['keys' => json_encode(array_keys(\is_array($args) ? $args : []))]); | |
| 32 | 33 | |
| 33 | 34 | return new JsonResponse(['cron' => true, 'args' => $args]); |
| 34 | 35 | } |
| @@ -28,7 +28,8 @@ final class DemoController | |||
| 28 | { | 28 | { |
| 29 | $args = json_decode($request->getContent(), true); | 29 | $args = json_decode($request->getContent(), true); |
| 30 | // A body meant as a Command Invocation but rejected lands here: its secret must not reach the logs. | 30 | // A body meant as a Command Invocation but rejected lands here: its secret must not reach the logs. |
| 31 | - $logger->info('CRON Invocation received with the arguments {keys}', ['keys' => implode(',', array_keys(\is_array($args) ? $args : []))]); | 31 | + // Anyone can POST here: JSON-encoding the names escapes the line breaks that would forge log entries. |
| 32 | + $logger->info('CRON Invocation received with the arguments {keys}', ['keys' => json_encode(array_keys(\is_array($args) ? $args : []))]); | ||
| 32 | 33 | ||
| 33 | return new JsonResponse(['cron' => true, 'args' => $args]); | 34 | return new JsonResponse(['cron' => true, 'args' => $args]); |
| 34 | } | 35 | } |