Repository navigation
fix(gl): make doctor diagnose the node the git transport will use #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1e5b262
fix(gl): make doctor diagnose the node the git transport will use
beardthelion a5a4ef2
Merge origin/main into fix/doctor-probes-transport-node and address r…
beardthelion 77661b4
Merge remote-tracking branch 'origin/main' into fix/doctor-probes-tra…
beardthelion 79a5e2a
Merge remote-tracking branch 'origin/main' into fix/doctor-probes-tra…
beardthelion e3359e2
fix(gl): probe a prefixed transport base verbatim and sanitize the re…
beardthelion 1d6d181
fix(gl): classify the GITLAWB_NODE row from the env var when gl and t…
beardthelion 85d50bc
Merge remote-tracking branch 'origin/main' into fix/doctor-probes-tra…
beardthelion d276735
fix(gl): parse the transport probe body as bytes and dial a trimmed n…
beardthelion 7bba067
Merge remote-tracking branch 'origin/main' into fix/doctor-probes-tra…
beardthelion 5d20fcd
Merge origin/main into fix/doctor-probes-transport-node
beardthelion 53aff7d
fix(gl): compare the transport node to the trimmed --node before call…
beardthelion 6809c60
fix(gl): make the transport probe take the helper's plaintext, proxy …
beardthelion 871426e
Merge remote-tracking branch 'origin/main' into fix/doctor-probes-tra…
beardthelion e8e9901
Merge origin/main into fix/doctor-probes-transport-node
beardthelion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| //! The plaintext-http policy the git transport applies to a node URL, shared with | ||
| //! `gl doctor` so the diagnostic refuses exactly what the helper refuses. | ||
|
|
||
| /// Whether `url` is plaintext http, regardless of where it points. | ||
| pub fn is_http(url: &str) -> bool { | ||
| url::Url::parse(url.trim()) | ||
| .map(|u| u.scheme() == "http") | ||
| .unwrap_or(false) | ||
| } | ||
|
|
||
| /// Whether `url` would send git data off this machine in cleartext. | ||
| /// | ||
| /// True only for `http://` to a non-loopback host. RFC 9421 signs the request | ||
| /// but does not encrypt it, so on a plaintext hop the pack contents and the | ||
| /// `Signature` header are both readable, and a captured signature is replayable | ||
| /// for its freshness window against any host. | ||
| /// | ||
| /// Loopback is decided from the parsed address rather than a string match, so | ||
| /// `127.0.0.2`, `[::1]` and an IPv4-mapped `[::ffff:127.0.0.1]` are all | ||
| /// recognised as this machine. A value that does not parse, or that is not | ||
| /// http(s), is not this guard's business and returns false: it fails later with | ||
| /// its own error, and naming it a TLS problem would misdirect the reader. | ||
| pub fn is_insecure_remote(url: &str) -> bool { | ||
| let Ok(parsed) = url::Url::parse(url.trim()) else { | ||
| return false; | ||
| }; | ||
| if parsed.scheme() != "http" { | ||
| return false; | ||
| } | ||
| let Some(host) = parsed.host_str() else { | ||
| return false; | ||
| }; | ||
| let host = host.trim_end_matches('.').to_ascii_lowercase(); | ||
| if host == "localhost" { | ||
| return false; | ||
| } | ||
| // host_str() keeps the brackets on an IPv6 literal. | ||
| let bare = host.trim_start_matches('[').trim_end_matches(']'); | ||
| if let Ok(ip) = bare.parse::<std::net::IpAddr>() { | ||
| if ip.is_loopback() { | ||
| return false; | ||
| } | ||
| // An IPv4-mapped IPv6 literal hides a v4 loopback from is_loopback(). | ||
| if let std::net::IpAddr::V6(v6) = ip { | ||
| if let Some(v4) = v6.to_ipv4_mapped() { | ||
| if v4.is_loopback() { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| true | ||
| } | ||
|
|
||
| /// Whether a non-empty `GITLAWB_ALLOW_INSECURE_HTTP` value opts in: only `1` or | ||
| /// `true` (case-insensitive, after trim). Presence alone is not consent. | ||
| pub fn allow_insecure_http_value(raw: &str) -> bool { | ||
| let t = raw.trim(); | ||
| t.eq_ignore_ascii_case("1") || t.eq_ignore_ascii_case("true") | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn insecure_remote_is_plaintext_off_this_machine_only() { | ||
| for u in [ | ||
| "http://node.example.com:7545", | ||
| "http://10.0.0.5", | ||
| "http://[2001:db8::1]", | ||
| ] { | ||
| assert!(is_insecure_remote(u), "{u}"); | ||
| } | ||
| for u in [ | ||
| "http://127.0.0.1:7545", | ||
| "http://localhost:7545", | ||
| "http://[::1]:7545", | ||
| "http://[::ffff:127.0.0.1]:7545", | ||
| "https://node.example.com", | ||
| "not a url", | ||
| ] { | ||
| assert!(!is_insecure_remote(u), "{u}"); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn only_one_or_true_opts_in() { | ||
| for v in ["1", " TRUE ", "true"] { | ||
| assert!(allow_insecure_http_value(v), "{v:?}"); | ||
| } | ||
| for v in ["", "0", "false", "yes", "11"] { | ||
| assert!(!allow_insecure_http_value(v), "{v:?}"); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn is_http_reads_the_scheme_only() { | ||
| assert!(is_http("http://127.0.0.1")); | ||
| assert!(!is_http("https://127.0.0.1")); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.