Skip to content

DIST-018 — Public challenge in the playground: break the firewall #181

Done

Description

@jmmana

Parent epic: #132
Priority: P1

Objetivo

Add a level-based challenge to the playground: visitors try to get a secret out of a demo database through a guard. The baseline levels (keyword list, first-word check) can be beaten and show why those defenses fail; the sqlguardllm levels are the real challenge. A bypass of a sqlguardllm level is reported privately and credited in a hall of fame after the fix. It gives people a reason to share the project.

Scope

  • New page playground/challenge/ (or a "Challenge" mode in the existing page) with the same stack: static HTML, CSS and JS, Pyodide, sqlite3 in the browser. No backend, no analytics, no cookies, no storage; progress may live in the URL fragment.
  • Levels in playground/challenge/levels.json, each with a validator, a fresh in-memory SQLite database, a goal and a short story, in English and Spanish:
    • L1, keyword list (same rule as the keyword baseline in benchmarks/guards/run.py). Goal: change data.
    • L2, first-word check (same rule as the first-word baseline). Goal: delete rows.
    • L3, sqlguardllm with a hidden column. Goal: read the hidden value.
    • L4, sqlguardllm with a hidden column, a masked column and a row filter. Goal: read another branch's row.
  • Deterministic win check: the level's validator accepts the query, the query runs on a fresh database, and the goal check passes (secret in the result, or rows changed). The database is reset on every attempt.
  • After an L1 or L2 win: explain why the trick works and link docs/BENCHMARK.md and the attack gallery. The share link carries only the level and the result.
  • After an L3 or L4 win: never put the SQL in a URL. Show how to report it privately (GitHub private vulnerability reporting, per SECURITY.md) and link the hall of fame.
  • docs/HALL_OF_FAME.md: reporters are credited only after the fix is released. Starts empty. SECURITY.md links it.
  • README.md and README.es.md link the challenge from the Playground section.

Security impact

Everything runs in the visitor's browser, so the secrets are not secret to someone who reads the page source. The prize is a verified guard bypass, not the flag, and the page says so. Do not add real sqlguardllm bypasses, third-party findings or solutions for L3/L4 anywhere in the repository.

Criterios de aceptación

  • The challenge loads in the Playwright suite (playground/test): every level renders in English and Spanish, with no horizontal scroll at 360 px.
  • Playwright tests: one known solution solves L1 and one solves L2 (kept only in the tests, never shown in the UI); attacks from tests/corpus fail on L3 and L4; the database resets between attempts.
  • With a stubbed validator, an L3/L4 win shows the private-report instructions and puts no SQL in the URL (test).
  • Parity test: the challenge's baseline validators give the same accept/reject as the benchmark baselines on the benchmark corpora.
  • docs/HALL_OF_FAME.md exists and is linked from SECURITY.md; README.md and README.es.md link the challenge.
  • The playground workflow, ruff, mypy and pytest are green; after the Pages deploy the challenge URL returns HTTP 200.

Archivos relevantes

  • playground/index.html, playground/app.js, playground/engine.py, playground/style.css
  • playground/challenge/ (new), playground/test/
  • benchmarks/guards/run.py (baseline rules, for the parity test)
  • docs/HALL_OF_FAME.md (new), SECURITY.md, README.md, README.es.md, mkdocs.yml

Out of scope: package versions, .github/workflows/release.yml, PRs #155 and #156.

Claude API proposal (AGENTS.md)

Workflow run: https://github.com/jmmana/sqlguardllm/actions/runs/46439805866 · model claude-sonnet-5-5 · manifest in the run artifact. Review it against the code; model output is not validation evidence.

proposal.md

Proposal: DIST-018, a "break the firewall" challenge in the playground

Suggestions for the maintainer. Nothing here is implemented. Assumptions are labelled [A]; things I could not verify from the excerpts are in Open questions.

1. Goal

Ship a four-level challenge page in the playground:

  • L1 and L2 use the two home-made baselines and are beatable. They teach why keyword lists and first-word checks fail.
  • L3 and L4 use the real sqlguardllm validator. A bypass is reported privately and credited in docs/HALL_OF_FAME.md only after the fix is released.

Constraints from the issue stay fixed: static HTML/CSS/JS, Pyodide and sqlite3 in the browser, with no backend, analytics, cookies or storage. Progress may live in the URL fragment.

2. Files to change

New files:

  • playground/challenge/index.html, challenge.js, challenge.css
  • playground/challenge/levels.json
  • playground/challenge/baselines.py (the L1/L2 validators)
  • playground/test/challenge.spec.* and a fixtures file for the known L1/L2 solutions (tests only)
  • docs/HALL_OF_FAME.md (empty table plus the credit rule)
  • tests/test_challenge_parity.py

Edited files:

  • SECURITY.md (link the hall of fame)
  • README.md, README.es.md (link from the Playground section)
  • mkdocs.yml (nav entry for the hall of fame)
  • playground/engine.py only if the existing engine can't be reused as-is [A: it exposes a check()-style entry that challenge.js can call]

benchmarks/guards/run.py should stay untouched. See the parity item below.

3. Proposed implementation

Separate page, shared engine

I'd use a separate page, playground/challenge/, rather than a mode in index.html. That keeps the existing playground's tests and layout unaffected. challenge.js reuses the Pyodide bootstrap and engine loading from app.js. If that code isn't importable, extract only the bootstrap into a small shared module, as a separate prep commit, so the diff stays reviewable.

levels.json schema (one entry per level)

{
  "id": "L1",
  "validator": "keyword",
  "title": {"en": "...", "es": "..."},
  "story": {"en": "...", "es": "..."},
  "goal": {"en": "...", "es": "..."},
  "schema_sql": "CREATE TABLE ...; INSERT ...;",
  "goal_check": {"type": "rows_changed", "table": "accounts"},
  "policy": null
}
  • goal_check.type is one of secret_in_result (with secret) or rows_changed (with table).
  • L3 and L4 carry a policy object: hidden column for L3; hidden column, masked column and row filter for L4. I'd mirror the playground's existing policy format. [A: the playground already accepts a policy in a JSON shape I can reuse.]
  • The en and es strings live in the JSON so tests can iterate every level in both languages.

Win check (deterministic, per attempt)

  1. Open a fresh in-memory SQLite DB from schema_sql (reset on every attempt, never reused).
  2. Run the level's validator on the query. If it rejects, show the reason and stop.
  3. Execute the query, then evaluate goal_check:
    • secret_in_result: the secret string appears in any result cell.
    • rows_changed: row count or content differs from the pristine snapshot.
  4. All three must hold to win.

Run the query with a statement-level guard against runaway queries, for example a progress-handler row or step cap. Everything is client-side, so this protects the visitor's tab, not a server.

Baselines, with a parity guarantee

The issue requires L1/L2 to match the baselines in benchmarks/guards/run.py. Duplicating the rules in baselines.py invites drift, so I'd make the parity test the guard rail:

  • The challenge ships its own baselines.py for Pyodide.
  • tests/test_challenge_parity.py loads both implementations and asserts identical accept/reject on every case in the attack and legitimate corpora (bench.attacks(), bench.legitimate() as in tests/test_guard_benchmark.py).
  • Alternative, if the maintainer prefers a single source of truth: move the two baseline functions into an importable module that both run.py and the challenge load. That touches run.py, so I've listed it under Open questions rather than assuming it.

Post-win behaviour

  • L1/L2 win: explain why the trick works, and link docs/BENCHMARK.md and docs/ATTACK_GALLERY.md. The share link (URL fragment) carries only level and result (e.g. #L1=won), never the SQL.
  • L3/L4 win: show private-reporting instructions (GitHub private vulnerability reporting, per SECURITY.md) and a link to the hall of fame. No SQL goes into the URL, DOM attributes, or any share link. Clearly state that the page is client-side, so the flag is readable from the source and the prize is a verified guard bypass, not the flag.

I'd also suggest the report instructions tell people to reproduce the bypass against the published package and include the version, so the maintainer doesn't have to trust the in-browser result.

Hall of fame

docs/HALL_OF_FAME.md starts with an empty table (reporter, date, release containing the fix) and a short rule: credit only after the fix ships. Link it from SECURITY.md and mkdocs.yml.

Hard rule: no bypasses in the repo

Per the issue, no real sqlguardllm bypass, third-party finding, or L3/L4 solution anywhere in the repository, including tests, fixtures, comments, commit messages and branch names. L1/L2 known solutions live only in the Playwright tests, never in the UI, and must be written so they are demonstrably baseline-only. They must not double as guidance for L3/L4.

4. Tests

Playwright (playground/test):

  1. Every level renders in en and es, with no horizontal scroll at a 360 px viewport.
  2. One known solution solves L1 and one solves L2 (kept in the test file only).
  3. Representative attacks from tests/corpus are rejected on L3 and L4. Load them from the corpus at test time rather than copying them into the test file.
  4. The database resets between attempts: run a mutating L1 solution, then confirm the next attempt sees pristine data.
  5. With a stubbed validator forced to accept, an L3/L4 win shows the private-report instructions, and location.href / location.hash contain no SQL (assert on the fragment and on any generated share link).

Python (pytest):

  1. tests/test_challenge_parity.py: baseline accept/reject parity against the benchmark corpora.
  2. A small test that levels.json has both languages for every string field and that every level's validator is a known key.

Docs and CI checks:

  1. HALL_OF_FAME.md exists and SECURITY.md links it; both READMEs link the challenge (simple string or link-presence assertion).
  2. The playground workflow, ruff, mypy and pytest are green. The post-deploy HTTP 200 check on the challenge URL is a manual or workflow step after Pages publishes.

5. Scope control

To keep the PR reviewable, I'd split it:

  • PR A: page, levels, baselines, win check, L1/L2 flow, parity test.
  • PR B: L3/L4 wiring with the stubbed-validator test, hall of fame, SECURITY/README/mkdocs links.

Out of scope, per the issue: package versions, .github/workflows/release.yml, PRs #155 and #156.

6. Open questions

  1. Baseline source of truth: keep a duplicate baselines.py guarded by the parity test, or refactor benchmarks/guards/run.py so both import one module? The first is smaller; the second removes drift risk.
  2. Pyodide and sqlglot availability: does the existing playground already load sqlglot and the sqlguardllm package in Pyodide, at what version, and is the policy shape reusable for L3/L4? I couldn't see playground/engine.py or app.js.
  3. Mode versus page: the issue allows either. I proposed a separate page; confirm.
  4. Reporting channel wording: is GitHub private vulnerability reporting enabled on the repo today, and should the instructions name a fallback contact if it's disabled?
  5. Hall of fame format: table columns, and whether reporters can opt for anonymity.
  6. Query cost cap: is a step/row cap acceptable for the in-browser executor, and what limit?
  7. Dialect: assume SQLite for all levels [A]; confirm no other dialect is wanted for L3/L4.
  8. Fragment contents: is level plus result enough, or should it also encode a locale?

Activity

  1. added
    type:feature
    area:security
    area:playground
    size:m
    p1
    on Nov 30, 2026
  2. jmmana commented on Nov 30, 2026

    @jmmana
    OwnerAuthor

    /warcodex proveedor=claude cuenta="Warlock"

  3. jmmana commented on Nov 30, 2026

    @jmmana
    OwnerAuthor

    WarCodex: encolado, posición 1.

  4. jmmana commented on Nov 30, 2026

    @jmmana
    OwnerAuthor

    WarCodex: empezó a trabajar en este issue (intento 1).

  5. jmmana commented on Nov 30, 2026

    @jmmana
    OwnerAuthor

    WarCodex abrió un PR para esta issue: pendiente de revisión.

    Base: main · rama: warcodex/issue-181

  6. jmmana commented on Nov 30, 2026

    @jmmana
    OwnerAuthor

    WarCodex: PR abierto: #184

  7. 5 remaining items

  8. jmmana commented on Nov 30, 2026

    @jmmana
    OwnerAuthor

    WarCodex: Bloqueada — la tarea quedó bloqueada.

    Motivo: El CI del PR #184 vuelve a fallar con el mismo error tras la vuelta de CI 1: hace falta una decisión (corregirlo a mano, reintentar o cerrar).

    Qué hacer: Revisa el detalle en el panel y, cuando esté resuelto, reintenta desde el panel.

    Detalle de la tarea en el panel: https://warcodex.warlockcode.com/cola/38d21069-ed68-4557-bfb4-3b1d99d01b79

  9. jmmana commented on Nov 30, 2026

    @jmmana
    OwnerAuthor

    WarCodex: listo, PR fusionado: #184

  10. jmmana commented on Nov 30, 2026

    @jmmana
    OwnerAuthor

    Delivered in #184 (merged) and #187 (the Pages deploy did not include playground/challenge/; fixed and verified).

    Verified live in a real browser at https://jmmana.github.io/sqlguardllm/playground/challenge/ (HTTP 200; levels.json and engine.py 200; Hall of fame https://jmmana.github.io/sqlguardllm/HALL_OF_FAME/ 200): the four levels load; the known L1 solution (SELECT adjust_balance(1, 50)) wins; on L3 the literal secret from levels.json does not win and SELECT token FROM vault is rejected with hidden_column; on L4 SELECT ssn FROM clients is rejected with hidden_column.

    A Sonnet 5.5 review before merging found one blocker (the L3/L4 secrets were static in levels.json, so typing the literal won): fixed with a per-attempt secret and tests (f1473ed). All PR checks green. Follow-ups not blocking (reviewer's should-fix list): error handling around the validate call, a stronger L3/L4 attack test, 360 px check with a win panel, and a request-recording test. Closing because every acceptance criterion is met.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:playgroundarea:securityp1size:mtype:featurewarcodex:listo

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions