Repository navigation
refactor(webarena): read public replay site logins only from the repository env file - #161
Conversation
…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.
There was a problem hiding this comment.
This review found 2 issue(s), including 2 blocking issue(s).
| if any(password in text for password in passwords): | ||
| raise ValueError(f"site password in public report: {path.name}") |
There was a problem hiding this comment.
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.
| for site in sites: | ||
| self._credentials(site) |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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_webarenastill readsos.environ.load_runtime_envstill 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_credentialis used, the meaning of--env-fileis 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 #159is accurate once these are fixed. - Test strength, by mutation:
- Reading
os.environin_credentialsfails 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.
- Reading
row["error"]type: it is always a string on both row paths, so.replacecannot raise onNone.- Isolation: nothing under
harness/browser_use/changed, andknown_site_secretsis unchanged.publication.pyimporting fromharness.environments.webarena.topologyfollows 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.pyandtests/test_env_file.pygave 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.
|
Review round 1: all three findings are fixed, none disputed.
A new effect to check: Local: lint gate passed; |
There was a problem hiding this comment.
This review found 1 issue(s), including 1 blocking issue(s).
| for password in sorted({item for item in passwords if item.strip()}, key=len, reverse=True): | ||
| text = text.replace(password, "[REDACTED]") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This review found 1 issue(s), including 1 blocking issue(s).
| html.escape(password), | ||
| json.dumps(password)[1:-1], |
There was a problem hiding this comment.
P2: Escaped passwords can survive the new projection/redaction boundary. For a configured password a"&b, redact_site_passwords('a"&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.
|
Follow-up to the comment above: ocr-review on beaa65b raised one more P1, and d42dc9e fixes it. Escaped password surviving redaction. Tests use a password with a backslash and quotes, through 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. |
|
Follow-up: ocr-review on d42dc9e raised one more P2, and 7b987e1 fixes it. HTML text and composed escapes surviving redaction. Tests cover 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. |
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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.
|
Follow-up: ocr-review on 7b987e1 raised one more P1, and 5d68d00 fixes it. Password escaped by the 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. |
There was a problem hiding this comment.
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("'", "\\'"), |
There was a problem hiding this comment.
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.
|
Follow-up: ocr-review on 5d68d00 raised one more P1, and 735e5eb fixes it. Control character in a Local: lint gate passed; the same pytest targets gave 2401 passed, 5 skipped, with golden snapshots unchanged. |
There was a problem hiding this comment.
✅ Re-review complete · 735e5eb
No findings in this incremental review.
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 2
Head reviewed: 735e5eb. No defects found.
Round 1 findings
All three are fixed.
- Trace and validation:
_run_taskredactserrorandvalidationbefore it builds theevaluate_resultstep. Removing either the redaction or theredact_textpass-through inrun_evaluationmakes tests fail. - Package check:
buildrefuses the HTML-escaped and JSON-escaped forms. Packaged bytes do not change, and a report without the password still packages. - Preflight:
verify_runtimecalls_login_credentialsfor every site with a_login_<site>handler, which is the same dispatch_prepare_impluses. It runs before Playwright starts.
What I verified
- Single source:
_credentialsandredact_login_passwordsboth read throughrepository_credential, so the login and the redaction use the same value. Neitherload_runtime_envnorselect_env_filecan reach that function. - Other login path:
os.environno longer supplies a login anywhere underpublic_webarena/. The diagnostic runtime smoke logs in throughWebArenaEnvironment.prepare, so it follows the same rule. - Issue scope:
credentials_envnames are kept,--env-filestill 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 #159holds. - Error paths: every
traceback.format_exc()inrunner.pyreaches a saved row only after redaction. The console line prints the redactedrow["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_configdoes dropcredentials_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.pypasses. - Isolation: nothing under
harness/browser_use/changed, andknown_site_secretskeeps 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
ruffcommands 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 2gave 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_textpass-through- package check
- decoded-HTML match in the package check
- projection redaction
- preflight login check
- inline
credentialsrejection
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.
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.WebArenaEnvironmentreads the variables named bycredentials_envthroughrepository_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, theload_runtime_envdocstring, the example README and the trajectory protocol.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.verify_runtimestops 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:
errortext, theevaluate_resulttrace step andvalidationreprescapespublic_projection(reports and public bundle)buildreprEvidence 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.pygainsconfigured_site_secrets, which skips unset values.known_site_secretsstays strict for Browser Use, and nothing underharness/browser_use/changed.Test plan
ruff checkwithF,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.--env-filestill supplies an ordinary setting.run_evaluationwith a mocked browser and Docker writes no password toattempts.jsonl, for an environment failure and for an evaluator failure._run_taskwith an execution error, a failing evaluator result and an evaluator exception leaves no password in the serialized row.credentials_envand lets a site without a login omit it.buildrefuses a report that contains a registered password in literal, HTML-escaped, JSON-escaped,repror combined form, and accepts a report without it.run_evaluationfor an environment failure and an evaluator failure.public_projectionand in the_run_taskrow.tests/package_smoke.py. CI covers them. No real WebArena site was logged in to.