Skip to content

Commit ee425b4

Browse files
committed
Harden formwatch for enterprise use
A large, mostly additive pass that keeps the existing CLI, output shapes, and on-disk formats backward compatible (one deliberate exception: --submit is now gated, see below). It covers five axes. Authorized use. A canonical notice (src/legal.rs, docs/legal.md, NOTICE, README, HTML footers) is printed by `formwatch legal`, surfaced as a reminder on test/monitor, and enforced: --submit refuses to run (exit 2) until acknowledged via --accept-terms, config, or FORMWATCH_ACCEPT_TERMS. Observability and configuration. tracing-based diagnostics on stderr (-v/-vv/--quiet, --log-format json), an append-only screenshot-free JSON audit log, a formwatch.yml + FORMWATCH_* config layer with CLI > env > file precedence, a typed error enum (thiserror) alongside anyhow, a --fail-on fail|warn gate, --no-screenshots, --proxy/--insecure/ --no-sandbox, and per-host request pacing. Contracts and integrations. Every record carries schema_version; report gained --junit, --sarif, and --prometheus; test/monitor gained --junit/ --sarif/--out; regression webhooks (Slack or generic JSON); shell completions; and a man page. LLM semantic checks (optional, off by default). src/llm/ adds provider- agnostic "Error wording (LLM)" and "Instructions (LLM)" checks over OpenAI Chat Completions, Anthropic Messages, or any compatible endpoint, with a no-network mock. Never fatal (missing key / provider error / timeout / unparseable reply degrade to one Warn), best-effort PII redaction, input truncation, an on-disk verdict cache, retries with Retry-After, parallel checks, prompt-injection-resistant delimiting, and `doctor --probe-llm`. Baseline. src/baseline.rs records accepted findings at their current severity so CI fails only on new or worsened problems; it drives exit codes, the [BASELINED] annotation, notifications, and JUnit/SARIF output. Scale and serving. Deterministic sharding (monitor --shard INDEX/TOTAL), Prometheus metrics (report --prometheus), and a read-only service mode (formwatch serve) exposing /healthz, /readyz, /metrics, and /api/forms. Supply chain and CI. Dockerfile, cargo-deny policy, Homebrew template, Dependabot, release checksums + CycloneDX SBOM + build provenance, and CI jobs for MSRV, deny, coverage, and CodeQL, plus SECURITY.md and ADR 0002. Also fixes a latent cold-cache bug: the concurrent-safe Chrome download created the cache's parent but never the private temp directory the fetcher writes its archive into, so the first run with no system Chrome died with "Failed to create archive file". fmt, clippy -D warnings, and the full test suite (127 tests) pass.
1 parent 1b63d53 commit ee425b4

48 files changed

Lines changed: 6596 additions & 188 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.dockerignore‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
target/
2+
.git/
3+
.github/
4+
.formwatch/
5+
results/
6+
community-forms/
7+
docs/
8+
fixtures/
9+
tests/
10+
index.html
11+
*.md
12+
!README.md

‎.github/dependabot.yml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: cargo
4+
directory: /
5+
schedule:
6+
interval: weekly
7+
open-pull-requests-limit: 10
8+
groups:
9+
cargo-minor-patch:
10+
patterns: ["*"]
11+
update-types: ["minor", "patch"]
12+
13+
- package-ecosystem: github-actions
14+
directory: /
15+
schedule:
16+
interval: weekly
17+
open-pull-requests-limit: 10
18+
19+
- package-ecosystem: docker
20+
directory: /
21+
schedule:
22+
interval: weekly

‎.github/workflows/ci.yml‎

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55
branches: [master]
66
pull_request:
77

8+
env:
9+
CARGO_TERM_COLOR: always
10+
811
jobs:
912
test:
1013
runs-on: ubuntu-latest
@@ -13,9 +16,38 @@ jobs:
1316
- uses: dtolnay/rust-toolchain@stable
1417
with:
1518
components: clippy, rustfmt
19+
- uses: Swatinem/rust-cache@v2
1620
- run: cargo fmt --check
17-
- run: cargo clippy --all-targets -- -D warnings
18-
- run: cargo test
21+
- run: cargo clippy --all-targets --locked -- -D warnings
22+
- run: cargo test --locked
23+
24+
# The declared `rust-version` in Cargo.toml is a promise; this proves it.
25+
msrv:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: dtolnay/rust-toolchain@1.85.0
30+
- uses: Swatinem/rust-cache@v2
31+
- run: cargo check --all-targets
32+
33+
coverage:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: dtolnay/rust-toolchain@stable
38+
with:
39+
components: llvm-tools-preview
40+
- uses: Swatinem/rust-cache@v2
41+
- uses: taiki-e/install-action@cargo-llvm-cov
42+
# Unit-test coverage of the library and CLI. Browser-driven
43+
# integration tests are exercised by the `test` job but excluded
44+
# here to keep this job fast and deterministic.
45+
- run: cargo llvm-cov --lib --bins --lcov --output-path lcov.info
46+
- uses: actions/upload-artifact@v4
47+
with:
48+
name: coverage-lcov
49+
path: lcov.info
50+
if-no-files-found: error
1951

2052
audit:
2153
runs-on: ubuntu-latest
@@ -25,6 +57,12 @@ jobs:
2557
with:
2658
token: ${{ secrets.GITHUB_TOKEN }}
2759

60+
deny:
61+
runs-on: ubuntu-latest
62+
steps:
63+
- uses: actions/checkout@v4
64+
- uses: EmbarkStudios/cargo-deny-action@v2
65+
2866
# Build-only on macOS/Windows: catches platform-specific compile breaks
2967
# (chromiumoxide/tokio have per-OS cfg'd bits) without spending CI time
3068
# on a headless-Chrome download in every job — the unit tests are pure
@@ -37,4 +75,23 @@ jobs:
3775
steps:
3876
- uses: actions/checkout@v4
3977
- uses: dtolnay/rust-toolchain@stable
40-
- run: cargo build
78+
- uses: Swatinem/rust-cache@v2
79+
- run: cargo build --locked
80+
81+
# Static analysis. Runs on pushes to the default branch only (not PRs)
82+
# because uploading results requires the security-events permission,
83+
# which isn't available to fork PRs.
84+
codeql:
85+
if: github.event_name == 'push'
86+
runs-on: ubuntu-latest
87+
permissions:
88+
security-events: write
89+
actions: read
90+
contents: read
91+
steps:
92+
- uses: actions/checkout@v4
93+
- uses: github/codeql-action/init@v3
94+
with:
95+
languages: rust
96+
- uses: github/codeql-action/autobuild@v3
97+
- uses: github/codeql-action/analyze@v3

‎.github/workflows/release.yml‎

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
name: release
22

3-
43
on:
54
push:
65
tags:
76
- "v*.*.*"
87

98
permissions:
109
contents: write
10+
id-token: write
11+
attestations: write
1112

1213
jobs:
1314
check-version:
@@ -50,15 +51,15 @@ jobs:
5051
targets: ${{ matrix.target }}
5152

5253
- name: Build
53-
run: cargo build --release --target ${{ matrix.target }}
54+
run: cargo build --release --target ${{ matrix.target }} --locked
5455

5556
- name: Package (unix)
5657
if: matrix.archive_ext == 'tar.gz'
5758
run: |
5859
name=formwatch-${{ matrix.target }}
5960
mkdir "$name"
6061
cp target/${{ matrix.target }}/release/formwatch "$name"/
61-
cp README.md LICENSE "$name"/
62+
cp README.md LICENSE NOTICE "$name"/
6263
tar czf "$name.tar.gz" "$name"
6364
6465
- name: Package (windows)
@@ -67,11 +68,49 @@ jobs:
6768
run: |
6869
$name = "formwatch-${{ matrix.target }}"
6970
New-Item -ItemType Directory -Path $name
70-
Copy-Item target/${{ matrix.target }}/release/formwatch.exe $name/
71-
Copy-Item README.md,LICENSE $name/
71+
Copy-Item "target/${{ matrix.target }}/release/formwatch.exe" $name/
72+
Copy-Item README.md,LICENSE,NOTICE $name/
7273
Compress-Archive -Path $name -DestinationPath "$name.zip"
7374
74-
- name: Upload release asset
75+
- name: Upload archive
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: formwatch-${{ matrix.target }}
79+
path: formwatch-${{ matrix.target }}.${{ matrix.archive_ext }}
80+
if-no-files-found: error
81+
82+
publish:
83+
needs: build
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@v4
87+
88+
- name: Download all built archives
89+
uses: actions/download-artifact@v4
90+
with:
91+
path: dist
92+
merge-multiple: true
93+
94+
- name: Generate checksums
95+
working-directory: dist
96+
run: sha256sum formwatch-* > SHA256SUMS.txt && cat SHA256SUMS.txt
97+
98+
- name: Generate an SBOM (CycloneDX)
99+
run: |
100+
cargo install cargo-cyclonedx --locked --quiet
101+
cargo cyclonedx --format json --all
102+
cp formwatch.cdx.json dist/formwatch.cdx.json
103+
104+
- name: Attest build provenance
105+
uses: actions/attest-build-provenance@v1
106+
with:
107+
subject-path: "dist/formwatch-*"
108+
109+
- name: Publish release
75110
uses: softprops/action-gh-release@v2
76111
with:
77-
files: formwatch-${{ matrix.target }}.${{ matrix.archive_ext }}
112+
generate_release_notes: true
113+
files: |
114+
dist/formwatch-*
115+
dist/SHA256SUMS.txt
116+
dist/formwatch.cdx.json

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/target
22
/.formwatch
33
*.log
4+
lcov.info
5+
*.cdx.json
6+
/dist

‎CHANGELOG.md‎

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,113 @@ project doesn't have a release yet, so everything below is grouped under
66

77
## [Unreleased]
88

9+
### Security
10+
11+
- An authorized-use notice now ships with the tool and is surfaced
12+
everywhere it matters: `formwatch legal` prints it, `docs/legal.md`
13+
carries the long form, `NOTICE` and the README cover it, and the HTML
14+
report and community dashboard carry a footer. `test`/`monitor` print a
15+
one-line reminder when the notice hasn't been acknowledged, and
16+
`--submit` (a real POST to a live system) now **refuses to run** until
17+
acknowledged via `--accept-terms`, `accept_terms: true` in config, or
18+
`FORMWATCH_ACCEPT_TERMS=1`.
19+
- New privacy and network controls: `--no-screenshots` (omit captured
20+
page content, which can contain personal data), `--proxy` and
21+
`--insecure` for corporate proxies/internal test hosts, `--no-sandbox`
22+
for containers, and per-host request pacing (`--per-host-delay-ms`)
23+
plus an append-only, screenshot-free JSON audit log (`--audit-log`).
24+
925
### Added
1026

27+
- **Optional LLM semantic checks** (`--llm` / `llm:` config): two
28+
provider-agnostic checks — "Error wording (LLM)" and
29+
"Instructions (LLM)" — that score the clarity of validation error
30+
messages and instructions/required-document guidance, addressing the
31+
heuristic wording limitation called out in the README. Providers are
32+
OpenAI (and any OpenAI-compatible endpoint via `--llm-base-url`),
33+
Anthropic, and a no-network `mock`. The feature is off by default,
34+
never fatal (missing key / provider error / timeout / unparseable reply
35+
degrade to a single `Warn`), redacts obvious PII, truncates input, and
36+
caches verdicts on disk. A low score is a `Warn` unless `--llm-fail` is
37+
set; `--llm-threshold` sets the pass bar.
38+
- LLM resilience and safety hardening: transient provider failures (HTTP
39+
429/5xx, network) are retried with exponential backoff honoring
40+
`Retry-After`; the two semantic checks run concurrently; page text is
41+
wrapped as untrusted data with delimiter neutralization and an explicit
42+
instruction not to follow embedded directions (prompt-injection
43+
resistance); provider token usage is logged at debug level; and
44+
`formwatch doctor --probe-llm` verifies provider connectivity and
45+
credentials.
46+
- **Baseline / allow-list of accepted findings** (`--baseline FILE`,
47+
`baseline:` config, `FORMWATCH_BASELINE`, and `formwatch baseline
48+
[--write]`): a finding is suppressed only when a baseline entry for the
49+
same URL and check is at least as severe as the current status, so a
50+
baselined `WARN` never absorbs a `FAIL`. Baseline-aware behavior covers
51+
`test`/`monitor` exit codes, a plain-text `[BASELINED]` annotation, and
52+
regression notifications; stale entries (improved or disappeared) are
53+
reported. This lets CI fail on *new* problems instead of failing on day
54+
one and being ignored.
55+
- Deterministic **sharding** (`monitor --shard INDEX/TOTAL`, `shard:`
56+
config, `FORMWATCH_SHARD`): checks only a stable slice of the configured
57+
forms, so a large registry can be split across several CI jobs or
58+
runners with no coordination — the union of all shards is the whole set
59+
and each form lands in exactly one shard every run.
60+
- **Baseline-aware JUnit and SARIF**: with `--baseline`, accepted findings
61+
render as `<skipped>` in JUnit (so an allow-listed `FAIL` doesn't fail
62+
CI) and as `baselineState: "unchanged"` with a SARIF `suppressions`
63+
entry, so code-scanning UIs treat them as pre-existing rather than new.
64+
- `test` and `monitor` accept `--junit` / `--sarif` (with `--out`), so a
65+
single CI job can run the checks and emit results in one step.
66+
- `report --prometheus` renders Prometheus text-exposition metrics
67+
(`formwatch_forms_total`, `formwatch_checks_failing`,
68+
`formwatch_checks_warning`, `formwatch_check_last_run_timestamp_seconds`,
69+
and per-check `formwatch_check_status`) for a scrape endpoint or a
70+
node_exporter textfile-collector directory.
71+
- A read-only **service mode** (`formwatch serve --addr HOST:PORT`, config
72+
`serve_addr`, or `FORMWATCH_SERVE_ADDR`): serves `/healthz`, `/readyz`,
73+
`/metrics` (Prometheus), and `/api/forms` (JSON) over the accumulated
74+
history, binding to `127.0.0.1:8080` by default and running until
75+
Ctrl-C. Deliberately read-only — no endpoint accepts a URL, triggers a
76+
run, or submits anything, so exposing it can't make formwatch touch a
77+
third-party site.
78+
- Structured diagnostics via `tracing`, written to **stderr** so
79+
machine-readable stdout is never corrupted: `-v`/`-vv`/`--quiet` and
80+
`--log-format json`.
81+
- Configuration file and environment-variable support
82+
(`src/config.rs`): a `formwatch.yml` (or `--config PATH`, or the user
83+
config dir) plus `FORMWATCH_*` variables, with CLI > env > file >
84+
default precedence.
85+
- New machine-readable report formats: `report --junit` (JUnit XML for
86+
CI dashboards; `FAIL` becomes `<failure>`, `WARN` becomes `<skipped>`)
87+
and `report --sarif` (SARIF 2.1.0 for code-scanning UIs).
88+
- Regression webhooks: `--webhook-url` on `test`/`monitor` posts to a
89+
Slack incoming webhook or a generic JSON endpoint when a check
90+
regresses to `FAIL` (`notify.on: always` to notify every run).
91+
- `formwatch completions <shell>` emits shell completions; a man page
92+
lives in `man/formwatch.1`.
93+
- Every persisted/JSON run now carries a `schema_version`
94+
(`history::SCHEMA_VERSION`), so downstream consumers can detect a
95+
breaking shape change instead of silently misreading newer data.
96+
- A typed `formwatch::error::Error` (`thiserror`) alongside the existing
97+
`anyhow` code, so embedders can match on failure cause; new modules are
98+
written against it and `anyhow::Error` interops via one variant.
99+
- Container and supply-chain packaging: a multi-stage `Dockerfile`,
100+
`deny.toml` (cargo-deny policy), a Homebrew formula template, a
101+
Dependabot config, and release checksums, a CycloneDX SBOM, and build
102+
provenance attestation in the release workflow.
103+
- CI now also runs an MSRV check, `cargo deny`, coverage
104+
(`cargo-llvm-cov`), and CodeQL.
105+
- `formwatch doctor [--json]`: checks the local environment (Chrome
106+
availability, writable history/audit directories, config, legal
107+
acknowledgement) without running a form, and exits non-zero if
108+
something a run depends on is broken.
109+
- `formwatch notify-test [--webhook-url URL]`: sends one synthetic
110+
regression so a webhook can be verified before relying on it.
111+
- `--fail-on fail|warn` (also `fail_on` in config and
112+
`FORMWATCH_FAIL_ON`): choose whether only `FAIL`, or also `WARN`,
113+
makes the process exit non-zero. Default is unchanged (`fail`).
114+
- A `SECURITY.md` vulnerability-disclosure policy.
115+
11116
- `formwatch init`, `formwatch test`, `formwatch monitor`, `formwatch report`
12117
(plain-text, `--html`, `--json`) — the whole CLI.
13118
- Seven built-in checks: submission flow (including multi-step wizard
@@ -55,6 +160,17 @@ project doesn't have a release yet, so everything below is grouped under
55160

56161
### Fixed
57162

163+
- A truly **cold** Chrome cache failed to populate: the concurrent-safe
164+
download created the cache's parent directory but never the private
165+
temp directory the fetcher writes its archive into, so the very first
166+
run on a machine with no system Chrome — or an empty cache — died with
167+
a bare `Failed to create archive file: No such file or directory`.
168+
Found while exercising the release test suite in a fresh environment;
169+
the temp directory is now created before the download.
170+
- All emitted errors/diagnostics now go through the logging pipeline, so
171+
`--log-format json` produces valid newline-delimited JSON on stderr
172+
instead of being interleaved with plain-text `eprintln!` warnings.
173+
58174
Found via code review and two independent review agents during
59175
development; every fix below was verified with a fixture reproducing
60176
the bug, not just reasoned about:

‎CONTRIBUTING.md‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ cargo fmt
1010
```
1111

1212
CI runs `fmt --check`, `clippy -D warnings`, and `test` on Linux, a
13-
build-only check on macOS/Windows, and `cargo audit` against advertised
14-
security advisories. Run the four commands above (plus `cargo audit` if
15-
you touched `Cargo.toml`) before opening a PR so CI doesn't surprise you.
13+
build-only check on macOS/Windows, an MSRV check against the
14+
`rust-version` in `Cargo.toml`, `cargo audit` against advertised security
15+
advisories, and `cargo deny` against the policy in `deny.toml`. Run the
16+
four commands above (plus `cargo audit` and `cargo deny check` if you
17+
touched `Cargo.toml`) before opening a PR so CI doesn't surprise you.
18+
19+
Anything user-visible should carry tests, and new library modules
20+
(`src/legal.rs`, `src/config.rs`, `src/notify.rs`, `src/export.rs`, ...)
21+
keep their pure logic in functions that are unit-testable without a
22+
browser.
1623

1724
When adding a dependency, set `default-features = false` unless you
1825
specifically want its defaults — chromiumoxide's defaults used to pull in

0 commit comments

Comments
 (0)