Skip to content

refactor(webarena): read public replay site logins only from the repository env file - #161

Merged
lanyue-llk merged 8 commits into
mainfrom
refactor/public-webarena-site-accounts
Nov 3, 2026
Merged

lanyue-llk merged 8 commits into
mainfrom
refactor/public-webarena-site-accounts

Conversation

@lanyue-llk

@lanyue-llk lanyue-llk commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What, why and how of this PR

Issues

Closes #159

Remaining owner decisions on redaction are in #160. #164 tracks the Rainbond slice, whose runtime config drops credentials_env, so a public run on a slice now stops at the preflight.

Summary

The public WebArena replay now follows the rule from #141: site logins come only from the repository .env.

  • Login: WebArenaEnvironment reads the variables named by credentials_env through repository_credential. The runtime config keeps its variable names, including names outside the site registry.
  • --env-file: it still selects the file for ordinary settings, and an exported variable wins over that file. Site logins ignore both, the same way the LLM diagnostics key and the Rainbond token already do. I chose ignoring over Web Fetch's rejection because this path allows any variable name, so a selected file cannot be checked against a fixed list. The rule is documented in the CLI help, the load_runtime_env docstring, the example README and the trajectory protocol.
  • Inline credentials: a runtime config containing them is now rejected. No example or generator writes them, and redaction could not know them. The issue did not name this route, so please check that no private runtime config relies on it.
  • Missing logins: verify_runtime stops the run before any browser starts, when a login site names no variables or names empty ones. Without this, a host that only exported its logins would record a failed attempt for every task.

Redaction

This path had no password redaction before, so this PR adds it from the same values the run uses:

Boundary Values removed or refused
Saved attempt error text, the evaluate_result trace step and validation Passwords named by the runtime config, as written or under up to two HTML, JSON or Python repr escapes
public_projection (reports and public bundle) Passwords named by the site registry, in the same spellings
Package build Refuses a report that still contains a registered password, as written or escaped for HTML, JSON or Python repr

Evidence that contains no password keeps its exact bytes, and the golden report hashes did not change. Rebuilding a report without site logins still works, so .env.example's "offline tools do not need them" stays true. #160 records the limits of this: a package built without the values is not checked, other variable names are covered only in the attempt's error and evaluator output, and the frozen trajectory's trace steps and HAR are not scrubbed.

topology.py gains configured_site_secrets, which skips unset values. known_site_secrets stays strict for Browser Use, and nothing under harness/browser_use/ changed.

Test plan

  • Lint gate (ruff check with F,TID252, then the default config): passed.
  • pytest tests/trajectory_replay tests/environments tests/test_golden_reports.py tests/test_env_file.py tests/test_local_path_privacy.py tests/test_packaging_hygiene.py -n 2: 2401 passed, 5 skipped. Golden snapshots are unchanged.
  • New tests:
    • An exported value and a selected file with different values change neither the login nor its redaction, and --env-file still supplies an ordinary setting.
    • A custom variable name is redacted.
    • An exported value cannot stand in for one missing from the file, and the preflight stops on it.
    • Inline credentials are rejected.
    • An end-to-end run_evaluation with a mocked browser and Docker writes no password to attempts.jsonl, for an environment failure and for an evaluator failure.
    • _run_task with an execution error, a failing evaluator result and an evaluator exception leaves no password in the serialized row.
    • The preflight stops on a login site with no credentials_env and lets a site without a login omit it.
    • build refuses a report that contains a registered password in literal, HTML-escaped, JSON-escaped, repr or combined form, and accepts a report without it.
    • A password with a backslash and quotes is redacted in its escaped spellings, including through run_evaluation for an environment failure and an evaluator failure.
    • HTML text escaping and composed HTML and JSON forms are redacted in public_projection and in the _run_task row.
    • A projection works with no credentials file.
  • Not run locally: the full suite and tests/package_smoke.py. CI covers them. No real WebArena site was logged in to.

…sitory env file

credentials_env names keep working, but their values now come through repository_credential, so an exported variable or --env-file cannot change a login. Inline credentials are rejected. The saved error text and the public report redact those same values, and a package containing one is refused.

@lexmount-ocr lexmount-ocr Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Review complete · a5d8a65

This review found 2 issue(s), including 2 blocking issue(s).

Comment on lines +237 to +238
if any(password in text for password in passwords):
raise ValueError(f"site password in public report: {path.name}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security · high
P1: Check decoded report content as well as raw bytes. build() copies existing reports without re-running public_projection, so reports generated without credentials (an explicitly supported workflow), or older reports, can contain escaped passwords. For example, with repository password secret"value, HTML containing secret"value or JSON containing secret\"value passes this literal check while disclosing the complete password to readers. _validate_binding does not validate arbitrary page content. Decode HTML entities and JSON string values for the secret check (while preserving the packaged bytes), and extend the package rejection test with escaped passwords. This is blocking because the newly added publication guard otherwise allows recoverable credentials into the archive even when their values are configured.

Comment on lines +137 to +138
for site in sites:
self._credentials(site)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug · medium
P2: The new preflight still accepts a required login with no credentials_env (or credentials_env: null). _credentials() returns {} in that case, so verify_runtime() succeeds and browsers start; _prepare_impl() then unconditionally invokes the site's login handler, where _login_credentials() raises on every attempt. This leaves the stated fail-fast requirement incomplete for shopping, shopping_admin, reddit and gitlab. Validate required login sites with _login_credentials() (while continuing to allow credential-free read-only sites), and add a preflight test with the credential reference block absent.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review, round 1

Head reviewed: a5d8a65. Three findings, all P2. The core change in #159 is sound; the gaps are in the redaction and preflight guards it adds.

Findings

P2, src/harness/trajectory_replay/public_webarena/runner.py:959: the redacted error is still saved unredacted in the trace.
_run_task copies the same error string into its evaluate_result trace step (runner.py:432, "output": ... else error). The new line scrubs only row["error"], so attempt.json and attempts.jsonl hold the password in trace[-1].output whenever an execution or evaluator error contains it. The comment at line 958, and the third limit in #160, justify this by saying the trace must stay what the frozen trajectory executed. That step is harness output, not a trajectory action. For a variable name outside the site registry, the projection does not catch it later either. I confirmed this by reading the code, not by running it. The new end-to-end test only covers the _environment_failure_row path, whose trace has a fixed message, so it cannot catch this.
Fix: scrub the evaluate_result output as well, for example by redacting error before that step is built or redacting that step in the same place. Add a test that goes through _run_task with a failing evaluator and asserts the password is absent from the whole serialized row. Update the comment and #160.

P2, src/harness/trajectory_replay/public_webarena/publication.py:237: the package check misses an escaped password.
The check is a literal substring match on rendered HTML and JSON. I ran build with the repository password secret"value:

Text in the report page Result
secret"value refused
secret"value not refused, archive written
secret\"value not refused, archive written

build copies existing reports without projecting them again, and the PR supports reports generated without site logins, so this check is the only guard for those reports. The upstream default accounts do not contain these characters, so the exposure is limited to custom passwords. For those passwords, the check gives false confidence.
Fix: also match the escaped forms, or compare against html.unescape(text) and the JSON-escaped form of each password, without changing the packaged bytes. Add those two cases to test_public_package_rejects_a_site_password_the_projection_missed.

P2, src/harness/trajectory_replay/public_webarena/webarena_environment.py:136: the preflight misses a login site with no credentials_env.
_credentials returns {} when credentials_env is absent or null, so verify_runtime succeeds and browsers start. _prepare_impl then calls the site's login handler unconditionally, and _login_credentials raises "credentials are missing" on every attempt. I confirmed that a fixture config without the block gives {} from _credentials and that error from _login_credentials. This is the outcome the comment at line 136 and the PR's "Missing logins" bullet say is prevented. It is not a regression, but the claim is broader than the code.
Fix: for a site that has a _login_<site> handler, call _login_credentials(site) in the preflight, and keep _credentials(site) for the others. Add a preflight test with the block absent.

Verified with no defect

  • Login source: no site login path in public_webarena still reads os.environ. load_runtime_env still copies values into the process environment, but nothing reads a login from there.
  • Scope of #159: the issue is complete apart from the findings above: repository_credential is used, the meaning of --env-file is decided and documented in the CLI help, docstring, README and protocol, the tests are updated, and the exported-value test exists. The runtime config keeps its variable names. Closes #159 is accurate once these are fixed.
  • Test strength, by mutation:
    • Reading os.environ in _credentials fails 7 tests.
    • Removing the projection password and the row["error"] scrub together fails the exported-value and end-to-end tests. I did not mutate the two separately.
  • row["error"] type: it is always a string on both row paths, so .replace cannot raise on None.
  • Isolation: nothing under harness/browser_use/ changed, and known_site_secrets is unchanged. publication.py importing from harness.environments.webarena.topology follows the existing module's use of that registry.
  • Golden snapshots: unchanged.
  • Lint: both ruff gates pass.
  • Local tests: tests/trajectory_replay/public_webarena, tests/test_golden_reports.py and tests/test_env_file.py gave 771 passed, 3 skipped.

CI at this head

Tests and static checks, Installation and packaging, Rendered reference and report checks, and Python 3.11 all pass. ocr-review fails with two blocking findings from the review bot. Both are real, and they match the second and third findings above, which I reproduced separately. I rate them P2 rather than the bot's P1 for the escaping case, for the reason given there.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Review round 1: all three findings are fixed, none disputed.

  • Password in the evaluate_result trace step (P2), d356fce. _run_task now redacts error before that step is built, so attempt.json and attempts.jsonl carry the scrubbed text. I also scrub validation, because the evaluator's exact-mismatch error is built from those checks and would otherwise leave the same value in the row. Tests go through _run_task (execution error, failing evaluator result, evaluator exception) and through run_evaluation (environment and evaluator failure), asserting on the serialized output. With the redaction disabled, the _run_task cases and the run_evaluation evaluator case fail. The nested walk in publication.py moved to a shared map_strings helper, and Decide the remaining limits of public WebArena password redaction #160 and the protocol doc are updated.
  • Escaped password passing the package check (P2), beaa65b. build now also matches HTML-escaped, JSON-escaped and JSON-inside-HTML forms, plus the \uXXXX form of a non-ASCII password. Packaged bytes do not change. test_public_package_rejects_a_site_password_the_projection_missed covers these forms, and a new test confirms a report without the password still packages.
  • Preflight missing a login site with no credentials_env (P2), 1d04310. A site with a _login_<site> handler now goes through _login_credentials; other sites keep _credentials. Tests cover the absent block and a site without a login.

A new effect to check: RainbondSlicePool.runtime_config rebuilds stateful site entries with URLs only, which drops credentials_env. From reading the code, every login on a slice already failed per attempt; with this preflight, a public run on a slice stops before any browser starts. I did not run a real slice. #164 tracks the fix, and the slice test stubs the login check until then.

Local: lint gate passed; pytest tests/trajectory_replay tests/environments tests/test_golden_reports.py tests/test_env_file.py tests/test_local_path_privacy.py tests/test_packaging_hygiene.py -n 2 gave 2374 passed, 5 skipped, with golden snapshots unchanged. CI on beaa65b is still running as I post this.

@lexmount-ocr lexmount-ocr Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Review complete · beaa65b

This review found 1 issue(s), including 1 blocking issue(s).

Comment on lines +35 to +36
for password in sorted({item for item in passwords if item.strip()}, key=len, reverse=True):
text = text.replace(password, "[REDACTED]")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security · high
P1: Redact escaped password representations before persisting diagnostics. This only matches the literal value, so a password containing a backslash (e.g. abc\def) survives when an error contains its Python repr or JSON-escaped form (abc\\def). There is a concrete repr-producing path in _login_reddit: captured alert messages are interpolated with messages[:3]!r, then the environment-failure handler passes the traceback through this helper before saving the attempt. If an alert echoes that password, the saved error still exposes it. Already-serialized evaluator diagnostics have the same problem, and registry-only package checks do not protect attempts or custom credential variable names. Match the relevant escaped forms as well as literal values, and add regression cases through the environment-failure and evaluator paths using passwords with backslashes/quotes.

@lexmount-ocr lexmount-ocr Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Review complete · d42dc9e

This review found 1 issue(s), including 1 blocking issue(s).

Comment on lines +43 to +44
html.escape(password),
json.dumps(password)[1:-1],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security · medium
P2: Escaped passwords can survive the new projection/redaction boundary. For a configured password a"&b, redact_site_passwords('a"&amp;b', [password]) returns the input unchanged: the HTML spelling here escapes quotes too, whereas HTML text can leave them literal. Likewise, JSON-escaping that HTML text is not covered by independently generating HTML and JSON spellings. These strings can remain in evaluator messages/validation and in public_projection output; write_latest_report renders that projected data and bundle export copies those reports without running the package check. The package validator does recognize the HTML-text example after unescaping, so a subsequent build rejects the report rather than receiving sanitized output. Cover HTML text escaping and composed HTML/JSON forms in the shared redactor, with projection and attempt-output regression cases, while leaving frozen trace evidence untouched.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Follow-up to the comment above: ocr-review on beaa65b raised one more P1, and d42dc9e fixes it.

Escaped password surviving redaction. redact_site_passwords matched only the literal value, so a password with a backslash or quote survived in a Python repr or JSON-escaped form, for example through messages[:3]!r in _login_reddit. A new site_password_spellings in config.py now supplies the literal, HTML-escaped, JSON-escaped and repr forms, and both redaction and the package check use it. Passwords with only alphanumerics and dots have one spelling, so they behave as before.

Tests use a password with a backslash and quotes, through redact_login_passwords and through run_evaluation for an environment failure and an evaluator failure.

Not covered: URL-encoded forms, in redaction or in the package check.

Local: lint gate passed; the same pytest targets gave 2383 passed, 5 skipped, with golden snapshots unchanged.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Follow-up: ocr-review on d42dc9e raised one more P2, and 7b987e1 fixes it.

HTML text and composed escapes surviving redaction. site_password_spellings escaped quotes in its only HTML form and never combined escapes, so a"&amp;b and JSON-escaped HTML passed through redact_site_passwords. It now covers HTML with and without quote escaping, and any two escapes applied in sequence. Trace steps of the frozen trajectory are still left untouched.

Tests cover public_projection and the _run_task row, which includes validation and the evaluate_result step.

Limits: more than two nested escapes and URL-encoded forms are not covered.

Local: lint gate passed; the same pytest targets gave 2397 passed, 5 skipped, with golden snapshots unchanged.

@lexmount-ocr lexmount-ocr Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Re-review complete · 7b987e1

This review found 1 issue(s), including 1 blocking issue(s).

lambda text: html.escape(text, quote=False),
lambda text: json.dumps(text)[1:-1],
lambda text: json.dumps(text, ensure_ascii=False)[1:-1],
lambda text: repr(text)[1:-1],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security · high
P1: repr chooses its quote delimiter from the entire string, so applying it only to the password misses valid repr-escaped passwords embedded in diagnostic text. For example, with password = "ab'cd" and text = repr('value "' + password), Python escapes the apostrophe in text, but repr(password)[1:-1] leaves it unescaped. None of the generated spellings matches, so redact_site_passwords(text, [password]) returns the secret unchanged. This affects persisted evaluator/error text and public projection, and the package check uses the same incomplete spellings. Generate both single-quoted and double-quoted Python string-body escape variants (including their compositions), and add a regression using repr of a larger message containing the opposite quote. This is blocking because the promised repr redaction can still publish a recoverable password.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Follow-up: ocr-review on 7b987e1 raised one more P1, and 5d68d00 fixes it.

Password escaped by the repr of a larger message. repr picks its quote from the whole message, so repr('value "' + password) writes ab\'cd even though repr of the password alone leaves the apostrophe alone. The spellings now include that single-quoted form, alone and combined with another escape, and a new test uses this exact message. The package check picks it up through the same helper.

This is the third round of finding spellings one at a time. Spelling matching can only cover the forms it lists, and more than two nested escapes and URL-encoded forms are still not covered. #160 is the place to decide whether that is enough.

Local: lint gate passed; the same pytest targets gave 2398 passed, 5 skipped, with golden snapshots unchanged.

@lexmount-ocr lexmount-ocr Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Review complete · 5d68d00

This review found 1 issue(s), including 1 blocking issue(s).

lambda text: json.dumps(text, ensure_ascii=False)[1:-1],
lambda text: repr(text)[1:-1],
# repr picks its quote from the whole message, so it may escape an apostrophe here too.
lambda text: text.replace("\\", "\\\\").replace("'", "\\'"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security · high
P1: The context-dependent repr spelling is still missed when the password also contains a control character. For example, with password = "ab'\tcd" and message = repr('value "' + password), the message contains an escaped apostrophe and an escaped tab together. Standalone repr(password) leaves the apostrophe unescaped, while this manual transformation leaves the tab literal; composing the transformations doubles existing backslashes rather than producing the required spelling. Consequently redact_site_passwords(message, [password]) leaves the secret intact, and _contains_site_password(message, (password,)) returns false. Such values are supported by the dotenv parser, so repr-formatted exception/evaluator messages can leak into saved attempts and pass the publication gate. Generate a complete forced-quote Python repr spelling (including control-character escapes) and add this case to both persistence and publication regression tests.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Follow-up: ocr-review on 5d68d00 raised one more P1, and 735e5eb fixes it.

Control character in a repr-escaped password. For ab'\tcd inside a larger repr, the apostrophe and the tab are both escaped, and the hand-written replacement from 5d68d00 left the tab literal. A forced-quote repr replaces it, so that spelling now escapes both. The redaction test and the package test cover this password.

Local: lint gate passed; the same pytest targets gave 2401 passed, 5 skipped, with golden snapshots unchanged.

@lexmount-ocr lexmount-ocr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Re-review complete · 735e5eb

No findings in this incremental review.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review, round 2

Head reviewed: 735e5eb. No defects found.

Round 1 findings

All three are fixed.

  • Trace and validation: _run_task redacts error and validation before it builds the evaluate_result step. Removing either the redaction or the redact_text pass-through in run_evaluation makes tests fail.
  • Package check: build refuses the HTML-escaped and JSON-escaped forms. Packaged bytes do not change, and a report without the password still packages.
  • Preflight: verify_runtime calls _login_credentials for every site with a _login_<site> handler, which is the same dispatch _prepare_impl uses. It runs before Playwright starts.

What I verified

  • Single source: _credentials and redact_login_passwords both read through repository_credential, so the login and the redaction use the same value. Neither load_runtime_env nor select_env_file can reach that function.
  • Other login path: os.environ no longer supplies a login anywhere under public_webarena/. The diagnostic runtime smoke logs in through WebArenaEnvironment.prepare, so it follows the same rule.
  • Issue scope: credentials_env names are kept, --env-file still selects ordinary settings, and precedence is documented in the CLI help, the docstring, the example README and the protocol. An exported value and a selected file with different values change neither the login nor its redaction. Closes #159 holds.
  • Error paths: every traceback.format_exc() in runner.py reaches a saved row only after redaction. The console line prints the redacted row["error"].
  • Inline credentials: no example or generator in the repository writes them. As the PR body says, only a private runtime config could still rely on them, and it would now stop with a clear error.
  • Rainbond slice: runtime_config does drop credentials_env, so a slice run on a login site now stops at the preflight instead of failing every attempt. That is older than this PR, and #164 tracks it.
  • Known limits: the remaining gaps in #160 match the code.
  • Evidence and golden reports: the projection returns the same values when no password is present. The diff changes no snapshots, profiles or receipts, and tests/test_golden_reports.py passes.
  • Isolation: nothing under harness/browser_use/ changed, and known_site_secrets keeps its strict behaviour.
  • Cost: per-string redaction measured about 9 microseconds with four alphanumeric passwords, so rebuilding the spellings for each string is not a practical problem.
  • Repository rules: the diff has no private hosts or local paths, the commits have no attribution lines, and .github/workflows/ is untouched.

Tests

  • Lint gate: both ruff commands passed.
  • Test run: pytest tests/trajectory_replay tests/environments tests/test_golden_reports.py tests/test_env_file.py tests/test_local_path_privacy.py tests/test_packaging_hygiene.py -n 2 gave 2401 passed, 5 skipped, matching the PR body.
  • Mutation checks: I reverted each of these in turn, and at least one test failed every time:
    • exported-value fallback in the login
    • exported value used for redaction
    • environment-failure redaction
    • validation redaction
    • redact_text pass-through
    • package check
    • decoded-HTML match in the package check
    • projection redaction
    • preflight login check
    • inline credentials rejection

CI

All check runs on 735e5eb succeeded, including "Tests and static checks" and "Installation and packaging". ocr-review reports 0 findings.

Not verified

No real WebArena site or Rainbond slice was used. The full local suite and tests/package_smoke.py were not run here; CI covers them.

lanyue-llk added a commit that referenced this pull request Nov 3, 2026
@lanyue-llk
lanyue-llk merged commit f60e0bd into main Nov 3, 2026
7 checks passed
@lanyue-llk
lanyue-llk deleted the refactor/public-webarena-site-accounts branch November 3, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Read public WebArena site logins only from the repository env file

1 participant