Prevent secrets from being fetched as remote relative paths - #977
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #977 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 27 27
Lines 9043 9069 +26
=========================================
+ Hits 9043 9069 +26 ☔ View full report in Codecov by Harness. |
Greptile SummaryThis PR prevents values accepted by secret-containing unions from being probed as relative paths against a remote configuration parent.
Confidence Score: 1/5The PR is not safe to merge until wrapped secret hints cannot trigger remote probes and remote-parent credentials are redacted from the new diagnostic. Direct Files Needing Attention: jsonargparse/_typehints.py, jsonargparse/_paths.py, jsonargparse/typing.py Security ReviewTwo credential-disclosure issues remain. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Value from remote config] --> B{Union directly contains recognized SecretStr?}
B -->|Yes| C[Disable remote-relative resolution]
B -->|No, including Annotated wrapper| D[Try path subtype normally]
C --> E{Value has explicit scheme?}
E -->|Yes| F[Fetch explicit remote path]
E -->|No| G[Try local relative path]
G -->|Path fails| H[Adapt as SecretStr]
D --> I[Probe remote parent plus value]
I --> J[Potential secret disclosure]
C --> K[Log skipped remote parent]
K --> L[Potential URL credential disclosure]
Reviews (1): Last reviewed commit: "Prevent secrets from being fetched as re..." | Re-trigger Greptile |
|



What does this PR do?
Checking whether a value is an existing path means accessing it. When a config is read from a URL or through fsspec, relative paths are resolved against the remote parent of that config, so a union type like
Path_fsr | SecretStrsent the secret itself to the remote server as a request for<remote parent>/<secret>, leaking it. The leak only needed the path subtype to be tried before the secret subtype, which is what happens with an inline secret in a remote config.Unions that include a secret type now resolve relative paths locally only. Values with an explicit scheme are still fetched, so an intentional
s3://bucket/password.txtkeeps working, and local relative paths are unaffected. Types without a secret keep the previous behavior.Changes:
typing.py: newis_secret_typehelper, true forjsonargparse.typing.SecretStrandpydantic.SecretStr._paths.py: newdisable_remote_relative_pathscontext manager, backed by a context variable thatPath.__init__checks before resolving a relative path against a remote parent. When it skips one, it debug logs the remote parent and the reason, never the path, since the path could be the secret._typehints.py: theUnionbranch ofadapt_typehintswraps the loop over subtypes in that context manager when any subtype is a secret type. Wrapping the whole loop also covers unions nested inside the subtypes.The changelog entry is under Fixed, the documentation notes the behavior with the secret types and adds a warning about it to the "Parsing URLs" section.
Before submitting