Skip to content

Commit a459052

Browse files
Redact index sources in uv.lock (#8333)
## Summary Closes #8296.
1 parent 23c80c5 commit a459052

File tree

3 files changed

+12
-41
lines changed

3 files changed

+12
-41
lines changed

crates/uv-pypi-types/src/requirement.rs

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -70,43 +70,6 @@ impl Requirement {
7070
self.source.is_editable()
7171
}
7272

73-
/// Remove any sensitive credentials from the requirement.
74-
#[must_use]
75-
pub fn redact(self) -> Requirement {
76-
match self.source {
77-
RequirementSource::Git {
78-
mut repository,
79-
reference,
80-
precise,
81-
subdirectory,
82-
url,
83-
} => {
84-
// Redact the repository URL, but allow `git@`.
85-
redact_credentials(&mut repository);
86-
87-
// Redact the PEP 508 URL.
88-
let mut url = url.to_url();
89-
redact_credentials(&mut url);
90-
let url = VerbatimUrl::from_url(url);
91-
92-
Self {
93-
name: self.name,
94-
extras: self.extras,
95-
marker: self.marker,
96-
source: RequirementSource::Git {
97-
repository,
98-
reference,
99-
precise,
100-
subdirectory,
101-
url,
102-
},
103-
origin: self.origin,
104-
}
105-
}
106-
_ => self,
107-
}
108-
}
109-
11073
/// Convert the requirement to a [`Requirement`] relative to the given path.
11174
pub fn relative_to(self, path: &Path) -> Result<Self, io::Error> {
11275
Ok(Self {
@@ -614,7 +577,15 @@ enum RequirementSourceWire {
614577
impl From<RequirementSource> for RequirementSourceWire {
615578
fn from(value: RequirementSource) -> Self {
616579
match value {
617-
RequirementSource::Registry { specifier, index } => Self::Registry { specifier, index },
580+
RequirementSource::Registry {
581+
specifier,
582+
mut index,
583+
} => {
584+
if let Some(index) = index.as_mut() {
585+
redact_credentials(index);
586+
}
587+
Self::Registry { specifier, index }
588+
}
618589
RequirementSource::Url {
619590
subdirectory,
620591
location,
@@ -625,7 +596,7 @@ impl From<RequirementSource> for RequirementSourceWire {
625596
subdirectory: subdirectory
626597
.as_deref()
627598
.and_then(Path::to_str)
628-
.map(str::to_string),
599+
.map(ToString::to_string),
629600
},
630601
RequirementSource::Git {
631602
repository,

crates/uv/tests/it/lock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6501,7 +6501,7 @@ fn lock_redact_index_sources() -> Result<()> {
65016501
]
65026502

65036503
[package.metadata]
6504-
requires-dist = [{ name = "iniconfig", specifier = ">=2", index = "https://public:heron@pypi-proxy.fly.dev/basic-auth/simple" }]
6504+
requires-dist = [{ name = "iniconfig", specifier = ">=2", index = "https://pypi-proxy.fly.dev/basic-auth/simple" }]
65056505

65066506
[[package]]
65076507
name = "iniconfig"

docs/configuration/indexes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Alternatively, credentials can be embedded directly in the index definition:
150150
```toml
151151
[[tool.uv.index]]
152152
name = "internal"
153-
url = "https://public:koala@https://pypi-proxy.corp.dev/simple"
153+
url = "https://public:[email protected]/simple"
154154
```
155155

156156
For security purposes, credentials are _never_ stored in the `uv.lock` file; as such, uv _must_ have

0 commit comments

Comments
 (0)