Skip to content

Preserve URL queries when writing direct origin metadata - #22356

Closed
zsol wants to merge 1 commit into
mainfrom
zsol/url-persistence-01-safe
Closed

zsol wants to merge 1 commit into
mainfrom
zsol/url-persistence-01-safe

Conversation

@zsol

@zsol zsol commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

direct_url.json records the origin of an installed distribution. Git URLs currently pass through display redaction when the metadata is constructed, which can redact query parameters needed to identify or access the source.

Add PersistSafeUrl to retain the parsed URL in memory and remove sensitive userinfo when serializing. Use it for direct URL metadata and index URLs. Serialization preserves the complete query string and retains a passwordless git username for ssh, git+ssh, and git+https URLs.

Parse persisted URLs without the ambiguity checks intended for human input, including when comparing installed sources against requirements. If a direct_url.json URL cannot be parsed, fall back to registry metadata; malformed metadata still produces an error.

@astral-sh-bot

astral-sh-bot Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

uv test inventory changes

This PR changes the tests when compared with the main base revision.

  • Added tests: 5
  • Removed tests: 0
  • Changed suites: 4
uv-pypi-types: +1 / -0

Added:

  • uv-pypi-types::parsed_url::tests::direct_url_deserializes_protocol_urls

Removed: none

uv-redacted: +2 / -0

Added:

  • uv-redacted::persistence::tests::persistence_removes_userinfo_and_preserves_query
  • uv-redacted::persistence::tests::persistence_retains_git_username

Removed: none

uv::pip: +1 / -0

Added:

  • uv::pip::pip_list::list_direct_url_falls_back_only_on_url_parse_errors

Removed: none

uv::pip_install: +1 / -0

Added:

  • uv::pip_install::pip_install::direct_url_json_accepts_ambiguous_path

Removed: none

@zsol
zsol force-pushed the zsol/url-persistence-01-safe branch from be603e3 to 405882c Compare October 9, 2026 15:46
@zsol
zsol added this pull request to stack #22393 October 9, 2026 15:50
@zsol
zsol force-pushed the zsol/url-persistence-01-safe branch from 405882c to 95f6e01 Compare October 12, 2026 11:50
@zsol
zsol force-pushed the zsol/url-persistence-01-safe branch from 95f6e01 to 0644502 Compare October 12, 2026 12:02
@zsol
zsol force-pushed the zsol/url-persistence-01-safe branch from 0644502 to f0d4b5b Compare October 13, 2026 09:23
@zsol
zsol marked this pull request as ready for review October 13, 2026 09:50
@zsol
zsol requested a review from EliteTK October 13, 2026 09:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T10:32:26.423353Z 2efe898 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@zsol zsol added the bug Something isn't working label Oct 13, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f0d4b5b385

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +67 to +68
Url::parse(url)
.map(DisplaySafeUrl::from_url)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve credential ambiguity checks for persisted URLs

When an existing direct_url.json contains ambiguous userinfo such as https://user/name:password@domain/a, Url::parse interprets user as the host and leaves name:password@domain in the path. Wrapping that result with DisplaySafeUrl::from_url bypasses the credential check, so commands such as uv pip freeze subsequently print the apparent password unredacted from dist.url. Before this change, DisplaySafeUrl::parse rejected the same metadata and treated the distribution as registry-installed; retain that protection or explicitly sanitize credential-like path and fragment content before accepting persisted URLs.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is a deliberate tradeoff. We apply ambiguity checks to human input, but use ordinary URL parsing for persisted metadata so valid paths containing : and @ are accepted. Credential-like text in those paths can therefore appear literally in output.

Comment on lines 605 to +606
Self::VcsUrl {
url: value.url.url().to_string(),
url: value.url.url().clone().into(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retain the Git username after stripping the VCS prefix

For an input such as git+https://[email protected]/repo.git, GitUrl has already removed the git+ prefix, so the value wrapped here has the scheme https, not git+https. PersistSafeUrl::serialize therefore does not recognize it as a Git URL and strips the passwordless git username, causing both direct_url.json and a later uv pip freeze to omit a username that the new persistence type explicitly promises to retain and that authenticated HTTPS Git servers may require. Preserve the VCS context when serializing or recognize the underlying HTTPS Git URL in this conversion.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is pre-existing. Before this PR, the same conversion wrote https://****@example.com/repo.git. The new code writes https://example.com/repo.git, so neither version preserves the git username.

@zsol
zsol force-pushed the zsol/url-persistence-01-safe branch from f0d4b5b to 88db503 Compare October 13, 2026 11:03
Comment thread crates/uv-pypi-types/src/direct_url.rs Outdated
/// Direct URL metadata whose URL has not yet been parsed.
#[derive(Deserialize)]
#[serde(transparent)]
// hide the `Serialize` and `Debug` implementations to avoid accidentally leaking credentials

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How are they "hidden"? what is this commenting on?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Codex says this just means we don't impl them here, I guess I'd put this kind of commentary in the doc comment explaining what invariants this type provides?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They're hidden in the sense that they're not implemented on DirectUrlMetadata, as opposed to above.

Hmm Codex originally put this in the doc comment when I asked it to capture why this is a struct wrapper instead of a "newtype" like ParsedDirectUrl, but I thought this was more implementation detail, and a user of the type shouldn't care

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"hidden" implies a more complex operation than "This type does not implement [Serialize] and cannot be serialized"

@zsol
zsol force-pushed the zsol/url-persistence-01-safe branch from 88db503 to 2efe898 Compare October 15, 2026 10:28
dir_info: _,
} => {
let mut url = Self::parse(url)?;
let mut url = url.as_url().clone();

@EliteTK EliteTK Oct 15, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Self::parse would call Self::reject_ambiguous_credentials and we're not doing that anymore, I believe that's unintended?

(it rejects e.g. https://user/name:password@domain/project)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see, you replied to a bot comment saying this is intentional...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes - let me know if you disagree with this though! You're more likely to change my mind than the clanker

@codspeed

codspeed Bot commented Oct 15, 2026

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

⚠️ 8 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 67 untouched benchmarks
⏩ 54 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ ⚠️ Simulation discover_workspace_from_all_members_with_excludes 140.1 ms 150.9 ms -7.12%
⚡ ⚠️ Simulation discover_workspace_from_all_members 156 ms 133.8 ms +16.58%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing zsol/url-persistence-01-safe (2efe898) with main (9385290)

Open in CodSpeed

Footnotes

  1. 54 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@EliteTK

EliteTK commented Oct 15, 2026

Copy link
Copy Markdown
Member

I think the problem was introduced/precedent was set in #21971 that we want to pass through query parameters etc. But the spec says we should not be persisting sensitive information in these files.

So I think we should be stripping rather than leaving things un-redacted. And then figuring out if we can work with that.

Also, worth noting that GitUrl clears the query in try_from so this PR will preserve it if it wasn't already cleared earlier, but currently it is cleared.

zanieb pushed a commit that referenced this pull request Oct 16, 2026
`SafeUrl` currently serializes the full URL, so fields can persist
credentials without an explicit choice. Add a type-level policy that
defaults to `Unserializable`; `Stripped` removes sensitive userinfo
while retaining the complete query, and `Raw` serializes the full parsed
URL. `Display` and `Debug` continue to redact passwords and recognized
sensitive query parameters. Index URLs in `pylock.toml` and publish URLs
in tool receipts use `Stripped`.

The inherent `serialize` and `serialize_internal` methods prevent those
method calls from falling through `Deref` to `Url`. Ordinary Serde
serialization of `SafeUrl` requires `Stripped` or `Raw`; the internal
serialization method requires `Raw`.

The serialization policies are an alternative to the wrapper types in
#22356, #22357, and #22358, combined in astral-sh#2712 for
comparison. `Stripped` and `Raw` follow the same serialization rules as
`PersistSafeUrl` and `CredentialPersistingUrl`. Using `SafeUrl<P>`
carries the policy through `VerbatimUrl`, stored fields, and
transformations such as `join`; shared implementations are generic over
the policy. The aforementioned stack also changes how `DirectUrl`
metadata is parsed and written; those changes are outside this PR's
scope. See also
#22600 (comment)

Stacked on #22599.

Co-authored-by: zaniebot <[email protected]>
@zsol
zsol removed this pull request from stack #22393 October 16, 2026 15:25
@zsol zsol closed this Oct 16, 2026

This branch was previously deployed

1 inactive deployment
automations — 2efe8985 Deployed Oct 15, 2026 by zsol via review / security review #51080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants