mirror of
https://github.com/LamGC/wp-asciiplayer.git
synced 2026-11-26 20:55:48 +00:00
fix: bound recording resources and add security regressions (#41)
Build and WordPress integration / Build and publish pristine package (push) Canceled after 0s
Build and WordPress integration / PHP 8.3 syntax and regression tests (push) Canceled after 0s
Build and WordPress integration / PHP 7.4 syntax and regression tests (push) Canceled after 0s
Build and WordPress integration / WordPress 6.3 / PHP 7.4 (push) Canceled after 0s
Build and WordPress integration / WordPress latest / PHP 8.2 (push) Canceled after 0s
Build and WordPress integration / Plugin Check (advisory) (push) Canceled after 0s
Build and WordPress integration / Build and publish pristine package (push) Canceled after 0s
Build and WordPress integration / PHP 8.3 syntax and regression tests (push) Canceled after 0s
Build and WordPress integration / PHP 7.4 syntax and regression tests (push) Canceled after 0s
Build and WordPress integration / WordPress 6.3 / PHP 7.4 (push) Canceled after 0s
Build and WordPress integration / WordPress latest / PHP 8.2 (push) Canceled after 0s
Build and WordPress integration / Plugin Check (advisory) (push) Canceled after 0s
- Bound recording bytes, JSON structure, events, markers, terminal dimensions and timestamp arithmetic before unsafe player allocation or scheduling. - Share validated playback data and metadata; cancel stale, failed and timed-out loads. - Add PHP 7.4-compatible predecode budgets and preserve supported v1/v2/v3 behavior. - Add localized errors, documented limits and 110 official/seeded recording fixtures. Verified 325 Node tests, native PHP 7.4/8.3 regression suites and 55 Chromium tests on each WordPress CI matrix. Preserve plugin version, vendor files and isolated package artifacts.
This commit is contained in:
Vendored
+169
@@ -0,0 +1,169 @@
|
||||
# TEST ONLY: deterministic recording-security corpus
|
||||
|
||||
This corpus exercises PR41's resource gates against ordinary, boundary and
|
||||
intentionally malformed asciicast input. It is **not** a collection to open in an
|
||||
unprotected terminal player. Do not upload generated boundary files to a real
|
||||
WordPress site, serve them publicly, or commit expanded large payloads.
|
||||
|
||||
Only small, readable `.cast` files are checked in. Large cases are compact
|
||||
literal/repeat recipes materialized one at a time in temporary storage. The
|
||||
largest possible file is **32 MiB + 1 byte**. There is no arbitrary size argument,
|
||||
unbounded fuzz loop, network request, remote command, or production-code import
|
||||
in the generator. The ordinary plugin package excludes the `tests` directory.
|
||||
|
||||
## Provenance and reproducibility
|
||||
|
||||
- `official-v1.cast`, `official-v2.cast`, and `official-v3.cast` are unmodified
|
||||
**native recordings** from pinned official CLI versions. Legacy CLI 1.4.0
|
||||
produced v1; CLI 3.0.1 produced v2 and v3. Their actual timestamps and PTY delays
|
||||
remain intact. See [PROVENANCE.md](PROVENANCE.md) and `provenance.json` for
|
||||
official source URLs, verified package hashes, commands and capture hashes.
|
||||
- `seeded-v*-valid.cast` are explicitly **normalized derivatives**, not raw CLI
|
||||
output. They retain the captured output text and the recorded format/dimension
|
||||
envelope, remove nondeterministic metadata, add seeded harmless UTF-8 output,
|
||||
and use fixed visible START/SEEK/END frames across a 12-second timeline. v2
|
||||
stores absolute time; v1/v3 store matching intervals. These are the interactive
|
||||
playback/seek controls.
|
||||
- Resource-boundary derivatives mutate one documented resource purpose. JSONL
|
||||
byte and line fillers are actual output events, not padding comments. Wide
|
||||
metadata, deep metadata and large valid grids are valid-format resource-unsafe
|
||||
cases; they must fail the intended policy rather than generic JSON syntax.
|
||||
- Blank/comment/indented lines, zero header dimensions and duplicate keys are
|
||||
marked `upstream-compatible`, independently of strict format provenance.
|
||||
- `malformed-v*` cases deliberately contain broken JSON and are labeled
|
||||
`intentionally-malformed`.
|
||||
|
||||
`recipes.mjs` uses real unsigned xorshift32 (`<<13`, `>>>17`, `<<5`) with the
|
||||
single allowed seed `0x41c0ffee` (1103167470). Randomized output chunks, text and
|
||||
bounded timings are deterministic. Equivalent purposes use all three formats
|
||||
where their semantics permit it. v1 has a whole-document 2 MiB budget and no
|
||||
marker/resize event types; those JSONL-only purposes apply to v2/v3. A fresh
|
||||
official PTY recording is not byte-identical; the checked-in raw captures are
|
||||
immutable, independently hash-pinned anchors, not regenerated during tests.
|
||||
|
||||
## Commands
|
||||
|
||||
Run from the repository root using the project's supported Node version:
|
||||
|
||||
```sh
|
||||
# List bounded, known case IDs, sizes and expected results.
|
||||
node tests/fixtures/security/generate.mjs --list
|
||||
|
||||
# Compare deterministic recipes to the golden manifest and verify every hash.
|
||||
node tests/fixtures/security/generate.mjs --verify
|
||||
|
||||
# Write exactly one known file to a new OS temporary directory.
|
||||
node tests/fixtures/security/generate.mjs --case markers-v2-over
|
||||
|
||||
# Independent corpus metrics plus actual production loader and player Core.
|
||||
node --test tests/js/security-fixtures.test.js tests/js/security-loader-fixtures.test.js
|
||||
|
||||
# All JavaScript checks, including both corpus suites.
|
||||
npm test
|
||||
|
||||
# Native PHP 7.4+; needs neither Node nor the asciinema CLI.
|
||||
php tests/php/run.php
|
||||
|
||||
# Real isolated WordPress/Chromium integration; see tests/e2e/README.md setup.
|
||||
npx --no-install playwright test tests/e2e/security-fixtures.spec.js
|
||||
```
|
||||
|
||||
The `--case` command prints the temporary path, byte count, SHA-256 and cleanup
|
||||
directory. Delete that directory after inspection. Test consumers clean up their
|
||||
own temporary files in `finally` blocks. Never replace the named case ID with a
|
||||
user-controlled arbitrary size. Large samples must stay outside source control.
|
||||
|
||||
When intentionally changing a recipe, run `--refresh` and review the complete
|
||||
manifest/hash/small-fixture diff, then rerun the checks above. This writes only
|
||||
the manifest and tiny derivative files; it never rewrites official captures or
|
||||
expands large cases into the repository. Provenance checks independently reject
|
||||
a changed raw baseline even if someone refreshes the golden manifest.
|
||||
|
||||
## Shared cross-language contract
|
||||
|
||||
`manifest.json` has `schemaVersion: 1`, an independently pinned `policy`, seed,
|
||||
and a `cases` array. Each case declares:
|
||||
|
||||
- `id`, `format`, `description`, `category`, `validity`, and `provenance`
|
||||
- Exactly one `source.file` relative to this directory, or ordered
|
||||
`source.segments: [{ "text": "literal UTF-8", "repeat": positiveInteger }]`
|
||||
- `bytes` and lowercase SHA-256 of the exact generated bytes
|
||||
- `expected.accepted` and exact `expected.jsError` (null for accepted controls)
|
||||
- Optional `boundary: {metric, limit, value}` and independent `metrics`
|
||||
- `safePlayback: true` only for the six tiny official/seeded accepted controls
|
||||
- Optional `playback` expectations for the normalized interactive controls
|
||||
|
||||
Concatenate the UTF-8 bytes of each literal repeated by its count in order. Do
|
||||
not normalize newlines, strip BOMs, reserialize JSON, execute text, or shell out
|
||||
to Node from PHP. The JavaScript reader verifies size and SHA-256 before use;
|
||||
the PHP reader streams at most 64 KiB at a time to one temporary file and checks
|
||||
the same identity before invoking the actual file/upload/sideload gates.
|
||||
|
||||
`expected.noDecodeAtOrAboveBytes` is a witness threshold for rejected JSON trees:
|
||||
the decoder must not see any tree input that large. Small safe headers or tiny
|
||||
version-discriminator scalar parses may still occur. Byte-over JSONL differs by
|
||||
consumer: PHP rejects from file size before any decode, expressed by the stronger
|
||||
`expected.phpNoDecodeAtOrAboveBytes: 1`; a browser stream must parse safe earlier
|
||||
records before discovering the final byte, then cancel without handing the
|
||||
recording to the player. This is not a claim that all streaming prefix parsing
|
||||
can or should be avoided.
|
||||
|
||||
## Coverage map
|
||||
|
||||
| Purpose | Case IDs | Boundary |
|
||||
| --- | --- | --- |
|
||||
| Official provenance and real playback | `official-v{1,2,3}`, `seeded-v{1,2,3}-valid` | Same native output; normalized equivalent timelines |
|
||||
| Zero/blank/multiline compatibility | `valid-v*-zero`, `valid-v{2,3}-filtered-lines`, `valid-v1-multiline-late-version` | Small actual files |
|
||||
| Format discrimination | `valid-v1-escaped-version`, `valid-v1-duplicate-version`, `valid-v1-long-first-line`, `invalid-v2-duplicate-version-wide` | v1 limits cannot leak into v2 |
|
||||
| Whole body bytes | `bytes-v{2,3}-{at,over}` | 33,554,432 / 33,554,433 bytes |
|
||||
| Legacy v1 bytes | `v1-bytes-{at,over}` | 2,097,152 / 2,097,153 bytes |
|
||||
| JSONL bytes including LF | `line-v{2,3}-{at,over}` | 262,144 / 262,145 bytes |
|
||||
| Events | `events-v{1,2,3}-{at,over}` | 100,000 / 100,001 events |
|
||||
| Physical JSONL work | `ignored-lines-v{2,3}-{at,over}` | 100,000 / 100,001 lines; exactly one output event |
|
||||
| Markers | `markers-v{2,3}-{at,over}` | 1,000 / 1,001 markers |
|
||||
| Header and late-resize axes | `dimensions-v*-{at,over}`, `late-resize-v{2,3}-dimensions-{at,over}` | 1,000 / 1,001 columns, otherwise safe |
|
||||
| Header and late-resize cells | `cells-v*-{at,over}`, `late-resize-v{2,3}-{at,over}` | 200×200 / 201×200; each axis remains valid |
|
||||
| v1 scalar/key allocation | `tokens-v1-{at,over}` | 400,000 / 400,001 tokens |
|
||||
| v1 container allocation | `containers-v1-{at,over}` | 100,016 / 100,017 containers |
|
||||
| JSONL scalar/key allocation | `line-tokens-v{2,3}-{at,over}` | 20,000 / 20,001 tokens |
|
||||
| Nesting | `depth-v{1,2,3}-{at,over}` | 15 / 16 container levels |
|
||||
| Recording timeline | `timeline-v{1,2,3}-{at,over}` | 2,147,483,647 / 2,147,483,648 milliseconds |
|
||||
| Relative timeline sum | `interval-timeline-v{1,3}-{at,over}` | Millisecond-order accumulation at / over the horizon |
|
||||
| Time metadata | `duration-v*-{zero,at,over}`, `idle-limit-v*-{zero,at,over}` | Zero remains valid; inclusive horizon applies |
|
||||
| Floating-point regressions | `time-v{1,3}-ms-rounding-over`, `time-v{1,3}-ms-sum-overflow`, `time-v2-output-nonprogress` | Valid JSON with unsafe upstream millisecond arithmetic |
|
||||
| Intentional bad syntax | `malformed-v1-json`, `malformed-v{2,3}-event` | Stable invalid-result controls |
|
||||
|
||||
The cells-over value is 40,200, not an assertion that every integer cell count
|
||||
has a valid integer grid. Event-only JSONL reaches the physical-line and event
|
||||
caps together; the ignored-line pair independently isolates physical-line work.
|
||||
There is no separate per-line cap on whole-document v1, and no JSONL-wide 400,000
|
||||
token budget: those distinctions are explicit rather than false all-format
|
||||
equivalence.
|
||||
|
||||
The corpus invariant suite independently parses tightly bounded test data to
|
||||
measure structure, verify valid/malformed labels, pin exact boundary values,
|
||||
and prove an unrelated limit is not masking the intended one. Only the six
|
||||
`safePlayback` controls use ordinary real pinned player Core playback. Separate
|
||||
tiny timestamp regressions use captured timers and bounded callbacks to verify
|
||||
upstream numeric behavior without scheduling long waits or an unbounded loop.
|
||||
Hostile/boundary recordings first exercise the production loader guard or PHP
|
||||
upload validator.
|
||||
|
||||
The supported raw timeline is about 24.85 days. Browser playback conservatively
|
||||
requires cumulative time divided by speed to fit the same signed timer ceiling;
|
||||
at 0.01×, this permits about 5.97 hours of source time. Per-event gap checks alone
|
||||
are insufficient because the player batches future output ahead of wall time.
|
||||
The v1/v3 rounding witness specifically distinguishes summing milliseconds from
|
||||
summing seconds before conversion; these two operations are not interchangeable.
|
||||
Browser tests use the existing isolated WordPress setup and check visible errors
|
||||
and recovery. Passing Node/PHP checks does not imply that a browser run occurred.
|
||||
|
||||
## Relationship to existing tests
|
||||
|
||||
Existing `hello.cast`, `replacement.cast`, `resize.cast`, `v1-pretty.cast`, and
|
||||
`v3-comments.cast` remain the ordinary UI regression fixtures. Existing inline
|
||||
small-limit unit tests remain useful for cancellation, option overrides, UTF-8
|
||||
failures and timing edge cases. This corpus adds durable official provenance,
|
||||
actual full-default at/over resource pairs, deterministic cross-language input,
|
||||
decoder-order witnesses and a common source for upload and playback integration;
|
||||
it does not replace those focused tests.
|
||||
Reference in New Issue
Block a user