Skip to content

fix: stop leaking credentials in resolved configs, debug request logs and the vLLM transport log - #3679

Merged
yuhezhang-ai merged 3 commits into
NVIDIA-NeMo:mainfrom
sven-rankov:sven-rankov/fix-2222-credential-leakage
Oct 3, 2026
Merged

yuhezhang-ai merged 3 commits into
NVIDIA-NeMo:mainfrom
sven-rankov:sven-rankov/fix-2222-credential-leakage

Conversation

@sven-rankov

@sven-rankov sven-rankov commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes both findings in #2222, one commit each, plus a related leak in the vLLM transport log that came up in review (third commit). The code has moved since the report: masking is now looks_like_secret_key in nemo_gym/secret_utils.py, and the debug print is in raise_for_status in nemo_gym/server_utils.py.

1. Secret masking (ERR-40044b75)

looks_like_secret_key only matched the lowercase substrings token, key and header. It now matches case-insensitively and also covers password, passwd, secret, credential, bearer, cookie and authorization. This only adds masking: every key masked today is still masked. The same masking is used by gym env resolve, the almost-server error, the W&B/MLflow run config and the recorded gym eval compare command.

authorization is needed because the masker walks into a headers mapping key by key, and Authorization matched none of the old substrings. For example, gym env resolve on the vcqa_agent config printed artifact_request_headers.Authorization as Bearer <HF_TOKEN> in plain text.

The issue also suggested auth, session, salt and signature. auth and session are left out because, as substrings, they would hide ordinary settings in this repo's configs (author, require_auth, max_concurrent_sessions, session_model, session_ttl_s); authorization covers the credential case of auth. No config uses a key containing salt or signature. I also kept the denylist instead of inverting it to an allowlist: an allowlist would change what every existing config displays, which is a bigger change than this fix.

recursively_hide_secrets on a config with fake values:

Key Before After
db_password sk-FAKE ****
DB_PASSWORD sk-FAKE ****
client_secret sk-FAKE ****
OPENAI_API_KEY sk-FAKE ****
apiKey sk-FAKE ****
Authorization inside a headers mapping Bearer sk-FAKE ****
policy_api_key **** ****
author, wandb_project unchanged unchanged
1 (int key) TypeError: argument of type 'int' is not iterable unchanged

2. Debug request logging (ERR-fcaebf7d)

With ++global_aiohttp_client_request_debug=True, a failed model call printed every request header, including the Authorization: Bearer <api key> that NeMoGymAsyncOpenAI adds to each call. It now prints the method and the URL without its query string, reusing _redacted_url as _format_upstream_error_log already does.

Output for a 401 from a local aiohttp server (fake key, abridged):

Before:

Request info: RequestInfo(url=URL('http://host/v1/chat/completions?api-key=sk-FAKE'), method='POST', headers=<CIMultiDictProxy('Host': 'host', 'Authorization': 'Bearer sk-FAKE', 'Accept': '*/*', ...)>, real_url=URL('http://host/v1/chat/completions?api-key=sk-FAKE'))
Response content: b'{"error": "invalid api key"}'

After:

Request info: POST http://host/v1/chat/completions
Response content: b'{"error": "invalid api key"}'

3. vLLM transport log (raised in review)

With NEMO_GYM_VLLM_TRANSPORT_LOG set, an HTTP error from the model endpoint was written to the log as repr(e). raise_for_status keeps the request headers on the exception, so the transport_error_response event contained the Authorization: Bearer <api key> header. The event now records only the error type, status, message, method and the URL without its query string; response headers are left out as well. raise_for_status is unchanged, so other callers still get the full exception metadata.

The generic transport_error event keeps repr(e): a ClientResponseError (including PermanentEndpointError) never reaches that handler, and the connection errors and timeouts that do carry no request headers.

The error field for a 400 from a local endpoint (fake key, abridged):

Before:

ClientResponseError(_PickleSafeRequestInfo(url='http://host/v1/chat/completions', method='POST', headers=<CIMultiDict('Host': 'host', 'Authorization': 'Bearer sk-FAKE', 'Content-Type': 'application/json', ...)>, real_url='http://host/v1/chat/completions'), (), status=400, message='Bad Request', headers=<CIMultiDict(...)>)

After:

ClientResponseError(status=400, message='Bad Request', method='POST', url='http://host/v1/chat/completions')

Closes #2222

Validation

All on the branch rebased onto main at d09fe41d3; git range-diff shows the first two commits unchanged by the rebase.

  • gym env test +entrypoint=responses_api_models/vllm_model +should_validate_data=true (the CI server-test command) in a fresh environment synced from uv.lock: 330 passed.
  • The vLLM model server end to end, as in the review: a fake API key, a local HTTP endpoint that returns 400, NEMO_GYM_VLLM_TRANSPORT_LOG set, one /v1/chat/completions call. Before, the error field contains 'Authorization': 'Bearer <fake>'; after, the fake key appears nowhere in the log file, and with ++global_aiohttp_client_request_debug=True nowhere in the console output either.
  • pytest on every unit-test file that imports a changed module (grep -rlE 'nemo_gym\.(secret_utils|server_utils)|from nemo_gym import (secret_utils|server_utils)' tests/unit_tests, 23 files) plus test_compare.py, test_public_api.py and test_openai_utils.py: 1801 passed, 27 skipped, 2 failed. The failures are test_cli.py::TestRunHelperServerReadiness::test_memory_profiler_uses_spawned_server_metadata and telemetry/test_connection_pool.py::test_multi_destination_waits_are_attributed_to_the_binding_limit, which fail the same way on unmodified main on macOS.
  • pytest tests/unit_tests --continue-on-collection-errors: 6435 passed, 175 skipped, 20 failed. The failures are in test_opensandbox_compose.py (11), test_ci_environment.py (3), telemetry/test_memory.py (2), test_cli.py (memory profiler), test_enroot_provider.py, test_sandbox_stop_retry.py and telemetry/test_connection_pool.py. All 20 fail the same way on unmodified main on macOS.
  • Reverted each source change and re-ran the new tests. The masking tests fail for the reported reasons: 9 keys (including Authorization) come out in plain text, the int key raises TypeError, and the case-insensitive overrides test fails. The debug-print test finds the fake bearer token in the output, and the transport-log test finds the fake key in the log file. The two exporter tests pass either way: they are guards that masking still switches the exporters off, not reproductions of the bug.
  • HF_TOKEN=<fake> gym env resolve with the vcqa_agent and openai_model configs: Authorization: Bearer <fake> before, Authorization: '****' after, and the fake value appears nowhere in the output.
  • Each commit passes test_global_config.py, test_exporters.py, test_server_utils.py and test_public_api.py on its own.
  • detect-secrets-hook 1.5.0 with the CI baseline (.github/workflows/config/.secrets.baseline) on each of the 8 changed files: passed.
  • pre-commit run --all-files: passed.

Rollouts

N/A: no agent, verifier or environment behavior changes. This only changes how configs are masked for display/export, what a debug-only print shows, and what the opt-in vLLM transport log records for HTTP errors.

Compatibility and benchmark impact

  • Keys matching the added words, in any case, now show as **** in gym env resolve, W&B/MLflow run configs and the recorded gym eval compare command. Live config values are unchanged.
  • MASKED_VALUE stays "****", so WANDBConfig/MLFlowConfig.is_available still treat a masked config as unconfigured. New tests run the real masker over both exporter configs to cover this.
  • The debug print is now Request info: <METHOD> <URL without query>. The signature of raise_for_status is unchanged, and .agents/skills/nemo-gym-debugging/references/request-boundary-visibility.md is updated.
  • In the opt-in vLLM transport log, the error field of transport_error_response events is now ClientResponseError(status=…, message=…, method=…, url=…) instead of the full repr, so it no longer includes request or response headers. http_status and raw_response_body are unchanged, and nothing in the repo parses error.
  • Known and unchanged: counter-style keys such as max_tokens are still masked because they contain token. Narrowing that is left for a separate PR, since it would unmask keys that are masked today.
  • No benchmark impact.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification.
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass).
  • New source files include the required Apache-2.0 SPDX header (N/A: no new files).
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

@copy-pr-bot

copy-pr-bot Bot commented Sep 24, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@nemo-automation-bot nemo-automation-bot Bot added the community-request Issue reported or requested by someone from the community label Sep 24, 2026
@sven-rankov
sven-rankov force-pushed the sven-rankov/fix-2222-credential-leakage branch from d506a15 to f2a1958 Compare September 24, 2026 14:06
@sven-rankov
sven-rankov marked this pull request as ready for review September 24, 2026 14:07
@yaoyu-33 yaoyu-33 added area:config Hydra configuration, schemas, composition, and compatibility bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface needs-review PR is ready for code review and waiting on a reviewer labels Sep 24, 2026
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Sep 25, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Sep 26, 2026
@yaoyu-33 yaoyu-33 removed the needs-review PR is ready for code review and waiting on a reviewer label Sep 26, 2026
@yuhezhang-ai

Copy link
Copy Markdown
Contributor

Thanks for fixing these credential leaks! Could you also cover the adjacent vLLM transport-log path in this PR?

With NEMO_GYM_VLLM_TRANSPORT_LOG enabled, the error handler records repr(e), which includes the Authorization header preserved on the exception by raise_for_status. I reproduced this through the vLLM adapter against a local HTTP endpoint returning 400: the updated debug output was clean, but the transport log's error field still contained the fake bearer token.

This behavior predates your changes, but it seems closely related to the credential-leak fix here. Could we sanitize the error details when writing that log and add a regression test checking that a fake API key is absent from the saved error event? A targeted change at the log writer would let us preserve the exception metadata other callers receive. Thanks!

sven-rankov and others added 2 commits October 2, 2026 21:35
`looks_like_secret_key` only matched the lowercase substrings `token`,
`key` and `header`, so other credentials were printed in plain text by
`gym env resolve` and the almost-server error, sent to W&B/MLflow as the
run config, and kept in the recorded `gym eval compare` command.

Match case-insensitively and also cover `password`, `passwd`, `secret`,
`credential`, `bearer`, `cookie` and `authorization`. The last one
catches an `Authorization` entry inside a headers mapping, which the
masker walks into key by key. This only adds masking: every key masked
before is still masked, and `MASKED_VALUE` stays "****", so the
exporters' `is_available` checks still treat a masked config as
unconfigured. Non-string OmegaConf keys (ints, enums) are matched on
their string form instead of raising `TypeError`.

`auth` and `session` are deliberately not matched: as substrings they
would hide ordinary settings such as `author`, `require_auth` and
`max_concurrent_sessions`.

Example, `recursively_hide_secrets` on a config with fake values:

  key                            before          after
  db_password                    sk-FAKE         ****
  OPENAI_API_KEY                 sk-FAKE         ****
  apiKey                         sk-FAKE         ****
  headers mapping: Authorization Bearer sk-FAKE  ****
  policy_api_key                 ****            ****
  author                         me              me
  1 (int key)                    TypeError       unchanged

Part of NVIDIA-NeMo#2222 (ERR-40044b75).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Tsvetan (Sven) Rankov <[email protected]>
With `global_aiohttp_client_request_debug=True`, `raise_for_status`
printed the whole aiohttp `RequestInfo`: every request header, including
the `Authorization: Bearer <api key>` that `NeMoGymAsyncOpenAI` adds to
each model call, and the URL query string. That is exactly the output
someone reads while debugging a 401.

Print only the method and the URL without its query string, reusing
`_redacted_url` as `_format_upstream_error_log` already does. The
`Request info:` prefix is kept so the debugging guide's search still
matches, and the guide now says headers are not printed. The signature
of `raise_for_status` is unchanged.

Example, a 401 from a model endpoint with the flag on (fake key):

  before:
    Request info: RequestInfo(url=URL('http://host/v1/chat/completions?api-key=sk-FAKE'),
      method='POST', headers=<CIMultiDictProxy('Authorization': 'Bearer sk-FAKE', ...)>, ...)
  after:
    Request info: POST http://host/v1/chat/completions

Closes NVIDIA-NeMo#2222 together with the previous commit (ERR-fcaebf7d).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Tsvetan (Sven) Rankov <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Oct 2, 2026
With `NEMO_GYM_VLLM_TRANSPORT_LOG` set, an HTTP error from the model
endpoint was logged as `repr(e)`. `raise_for_status` keeps the request
headers on the exception, so the `transport_error_response` event wrote
`Authorization: Bearer <api key>` to the log file.

Log only the error type, status, message, method and the URL without
its query string. Response headers are left out as well; the event
still has `http_status` and `raw_response_body`. `raise_for_status` is
unchanged, so other callers still receive the full exception. The
generic `transport_error` event keeps `repr(e)`: a `ClientResponseError`
never reaches that handler, and the connection errors and timeouts that
do carry no request headers.

Example, a 400 from the model endpoint with a fake key:

  before:
    ClientResponseError(_PickleSafeRequestInfo(url='http://host/v1/chat/completions',
      method='POST', headers=<CIMultiDict('Authorization': 'Bearer sk-FAKE', ...)>, ...), ...)
  after:
    ClientResponseError(status=400, message='Bad Request', method='POST',
      url='http://host/v1/chat/completions')

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Tsvetan (Sven) Rankov <[email protected]>
@sven-rankov
sven-rankov force-pushed the sven-rankov/fix-2222-credential-leakage branch from f2a1958 to 44b1b1b Compare October 2, 2026 20:56
@sven-rankov sven-rankov changed the title fix: stop leaking credentials in resolved configs and debug request logs fix: stop leaking credentials in resolved configs, debug request logs and the vLLM transport log Oct 2, 2026
@sven-rankov

Copy link
Copy Markdown
Contributor Author

@yuhezhang-ai Thanks for catching this, and for the repro! Fixed in 44b1b1b:

  • The transport_error_response event now logs the error as ClientResponseError(status=…, message=…, method=…, url=…): no request or response headers, and no URL query string.
  • raise_for_status is unchanged, so other callers still get the full exception metadata.
  • New test test_transport_log_error_event_omits_request_headers: a failed call with a fake bearer token goes through the real raise_for_status, and the test checks that the key is not in the log. It fails without the fix (and also with str(e)).
  • I re-ran your scenario (local endpoint returning 400, debug flag on): the fake key no longer appears in the debug output or the transport log.

The generic transport_error event still uses repr(e). ClientResponseError (including PermanentEndpointError) is caught by the clause above it, and the connection errors and timeouts that reach it carry no request headers. Happy to change it too if you'd prefer.

I also rebased onto current main (the first two commits are unchanged) and updated the PR description.

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Oct 3, 2026
@yuhezhang-ai

Copy link
Copy Markdown
Contributor

/ok to test 44b1b1b

@yuhezhang-ai yuhezhang-ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for addressing the logging issue! I rechecked this commit with a local HTTP 400 response through the vLLM client: credentials stay out of the transport log and debug output, while the original exception retains its request and response metadata. No further code changes requested; this addresses my earlier comment. Normal CI still needs to pass.

@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 3, 2026 02:10
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/37090232148

Merged via the queue into NVIDIA-NeMo:main with commit 3ef478d Oct 3, 2026
43 checks passed
ananthsub added a commit that referenced this pull request Oct 5, 2026
Resolve the import conflict in tests/unit_tests/test_global_config.py by keeping
both upstream's hide_secrets_in_overrides import (#3679) and this branch's
rollout_collection import.

Signed-off-by: Ananth Subramaniam <[email protected]>
ananthsub added a commit that referenced this pull request Oct 6, 2026
…vers (#3818, #4070, #3929, #4053) into `r0.7.0` (#4107)

## What

This PR only cherry-picks four already-merged `main` PRs into `r0.7.0`.
It adds no new code. The commits are applied in their `main` merge order
with `git cherry-pick -x`, so each commit message records its source
commit.

| Original PR | Commit on `main` | Change |
|---|---|---|
| #3818 | `325fb49d6` |
feat(data): collate declared tasksets |
| #4070 | `412efc730` | refactor:
name episode requests and sessions without "native" |
| #3929 | `1f2446c17` |
feat(config): deprecate agents without an environment server and fix the
migration script |
| #4053 | `89c065b0e` |
feat(config): support environment servers that front several agents |

## Why

#4070 and #4053 carry the `r0.7.0` label, but the automatic cherry-pick
workflow could not apply them: both hit merge conflicts on `r0.7.0`. The
workflow still reports success, so the failure was silent. #3818 was
intended for `r0.7.0` but never had the label.

#3929 is included because #4053 builds on it. Every #4053 conflict came
from #3929 changes to `nemo_gym/global_config.py`,
`scripts/add_legacy_agent_environment_servers.py`, and their tests. With
#3929 applied first, #4053 applies cleanly.

## Conflict resolution

Picking #3818 first removed one #4070 conflict. The remaining conflicts
were in tests that other PRs added on `main` after the branch cut:

- **#4070**: renames identifiers, comments, and test names; no behavior
change. Where the conflict was a test that exists only on `main`
(`single_agent_turn`, SWE-bench Pro, and Hermes
`test_agent_sessions.py`), the `r0.7.0` version is kept and the
`main`-only test is not brought in. In `single_agent_turn_legacy`, the
existing test is renamed to
`test_flat_rows_and_episode_requests_project_the_same_result` to match
`main`, and the `task_source` tests from a separate PR are left out.
- **#3929**: one import line in
`tests/unit_tests/test_global_config.py`. `main` also imports
`hide_secrets_in_overrides`, added by
#3679 and unused in this file, so
the `r0.7.0` import is kept.
- **#3818** and **#4053**: applied cleanly.

## Validation

- `pytest tests/unit_tests/test_global_config.py
tests/unit_tests/test_add_legacy_agent_environment_servers.py
tests/unit_tests/test_rollout_collection.py
tests/unit_tests/test_environment_server.py
tests/unit_tests/test_task_materialization.py
tests/unit_tests/test_benchmarks.py`: pass.
- `pytest environment_servers/single_agent_turn/tests` and `pytest
environment_servers/single_agent_turn_legacy/tests` (run separately):
pass.
- `pytest tests/unit_tests -n 8`: same failures as unmodified `r0.7.0`
and no new ones. The existing failures are local-environment tests in
`test_opensandbox_compose.py`, `test_sandbox_stop_retry.py`, and
`test_slurm_script.py`.
- `pre-commit run --files` on all changed files: pass.
- Checked for old names #4070 renames (`_native_request`,
`_native_episode_request_body`, `_native_session_locks`,
`_closed_native_sessions`): none remain. The few remaining "native row"
comments are also on `main`.
- SWE-bench Pro and Hermes server tests were not run locally (they need
per-server venvs); release-branch CI covers them.

## Rollout evidence

N/A. Each change was reviewed and validated on `main`. This PR only
carries them to the release branch: #4070 is a rename with no behavior
change, and the config changes are covered by the unit tests above.

---------

Signed-off-by: yaoyu-33 <[email protected]>
Signed-off-by: Ananth Subramaniam <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
Co-authored-by: Yu Yao <[email protected]>
Co-authored-by: Felipe Vieira Frujeri <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 44b1b1b8 Deployed Oct 3, 2026 by copy-pr-bot[bot] via release / finalize / notify #4227
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:config Hydra configuration, schemas, composition, and compatibility bug Something isn't working community-request Issue reported or requested by someone from the community complexity:low Localized change in one scope with a small, straightforward review surface sla:triage-overdue Review assignment is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[VDR][v0.5.0] Credential leakage

4 participants