Skip to content
3 changes: 2 additions & 1 deletion .claude/skills/sc-cli-reference/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ cargo run --bin sc -- serve --http <addr> <path> --tls [--tls-cert <pem> --tls-k
# --tls now — plaintext public needs
# --allow-public (or --read-only)
cargo run --bin sc -- serve fingerprint [<path>] # print (minting if absent) the serve-TLS
# SPKI fingerprint (sha256:<hex>)
# SPKI fingerprint (sha256:<hex>); needs a repo
# (.sc/) — found from the cwd, or <path>
cargo run --bin sc -- clone sc+https://host[:port]/repo <dst> # TLS clone (P32); accept-new
# TOFU: first connect pins into
# ~/.config/sc/known_hosts (SC_HTTPS_KNOWN_HOSTS
Expand Down
23 changes: 10 additions & 13 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -906,19 +906,16 @@ scale-&-reach horizon):
today; and a one-line fix to `SignatureObj.snapshot`'s now-stale doc
comment, which still describes the field as always a snapshot id even
though signing a transcript stores a transcript id there instead.
- **P32 follow-ons.** Four items named but not closed by the P32 TLS work,
deferred rather than silently dropped: (1) a `.sc`-existence check before
`sc serve fingerprint`/`--tls` auto-mint — today it happily mints
`~/.sc/serve-tls` even when run outside a repo; (2) a stderr warning when
an `SC_HTTPS_*` env knob (`SC_HTTPS_STRICT`/`SC_HTTPS_FINGERPRINT`/
`SC_HTTPS_KNOWN_HOSTS`) is set but the target URL is plaintext
`sc+http://` — a scheme-downgrade footgun where the knob silently does
nothing; (3) a client-side TLS handshake/read timeout — the server bounds
its side at 30s (the opening read), but the `sc+https://` client is
unbounded, so this folds into the existing deferred hostile-peer pass
alongside `read_frame_inner`'s unbounded frame-length allocation; (4)
`sc remote add` parse-validating `sc+http(s)://` URLs at add time, the
way `ssh://` already does, instead of deferring the parse to first use.
- **P32 follow-ons — shipped.** The four items the TLS work named: (1) `sc serve
fingerprint` and `--tls` auto-mint refuse a root with no `.sc/` instead of
minting there; (2) a stderr warning when an `SC_HTTPS_*` knob is set but the
URL is plaintext `sc+http://`; (3) the `sc+http(s)://` client bounds the connect, TLS handshake, opening and
status line (30 s inactivity) and the wire handshake (300 s, for a bucket
server's slow open), so a silent peer fails the connect as `ConnectionLost`,
and lifts both afterwards; (4) `sc remote add` parse-validates `sc+http(s)://` URLs
at add time like `ssh://` and the bucket schemes. The client bounds are not
configurable, and `read_frame_inner`'s frame-length allocation (covered by the
`MAX_OBJECT_SIZE` cap since P28) is unchanged.

- **P34 follow-ons (private branches, ADR-0044).** Deferred rather than
built: (1) `sc branch publish --squash` — collapse the sealed history into
Expand Down
9 changes: 8 additions & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,8 @@ fn main() -> Result<()> {
Some(ServeSub::Fingerprint { path }) => {
let root = match path {
Some(p) => p,
None => std::env::current_dir()?,
// Like every repo command, find the repo from a subdirectory.
None => scl_repo::layout::Layout::discover(std::env::current_dir()?)?.root,
};
println!(
"{}",
Expand Down Expand Up @@ -3912,6 +3913,12 @@ fn run_remote(op: RemoteOp) -> Result<()> {
if url.starts_with("ssh://") {
scl_repo::SshUrl::parse(&url)?; // fail fast on malformed URLs
}
// The reserved scheme prefix, not just the exact `://` form: a
// near miss such as `sc+https:/host/repo` would otherwise be
// recorded and later read as a local path.
if url.starts_with("sc+http:") || url.starts_with("sc+https:") {
scl_repo::ScHttpUrl::parse(&url)?; // fail fast on malformed URLs
}
if url.starts_with("sc+wal://") || url.starts_with("sc+s3://") {
scl_repo::BucketUrl::parse(&url)?; // fail fast on malformed URLs
}
Expand Down
96 changes: 96 additions & 0 deletions crates/cli/tests/remote_add_validation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//! `sc remote add` parse-validates the native network URL schemes at add time,
//! so a typo fails here and not at the first fetch (P32 follow-on).
use std::process::Command;

fn sc(dir: &std::path::Path, args: &[&str]) -> std::process::Output {
Command::new(env!("CARGO_BIN_EXE_sc"))
.args(args)
.current_dir(dir)
.output()
.expect("sc runs")
}

fn repo(tag: &str) -> std::path::PathBuf {
let root =
std::env::temp_dir().join(format!("scl-cli-remote-add-{tag}-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&root);
std::fs::create_dir_all(&root).unwrap();
assert!(sc(&root, &["init"]).status.success());
root
}

#[test]
fn malformed_http_urls_are_refused_at_add_time_and_good_ones_recorded() {
let root = repo("http");
for bad in [
"sc+http://",
"sc+http:///repo",
"sc+https://host:notaport/repo",
"sc+http://host:99999/repo",
"sc+https:/host/repo", // near-miss scheme: one slash
"sc+http:host/repo",
] {
let out = sc(&root, &["remote", "add", "origin", bad]);
assert!(!out.status.success(), "{bad} should be refused");
let list = sc(&root, &["remote", "list"]);
assert!(
String::from_utf8_lossy(&list.stdout).trim().is_empty(),
"{bad} must not be recorded"
);
}

for (name, good) in [
("plain", "sc+http://127.0.0.1:7777/repo"),
("secure", "sc+https://example.com/repo"),
] {
let out = sc(&root, &["remote", "add", name, good]);
assert!(
out.status.success(),
"{good}: {}",
String::from_utf8_lossy(&out.stderr)
);
}
let list = String::from_utf8_lossy(&sc(&root, &["remote", "list"]).stdout).into_owned();
assert!(list.contains("sc+http://127.0.0.1:7777/repo"), "{list}");
assert!(list.contains("sc+https://example.com/repo"), "{list}");

std::fs::remove_dir_all(&root).unwrap();
assert!(!root.exists(), "test must leave no residue");
}

/// With no path, `sc serve fingerprint` finds the repo from a subdirectory,
/// and outside any repo it refuses instead of minting.
#[test]
fn serve_fingerprint_discovers_the_repo_and_refuses_outside_one() {
let root = repo("fingerprint");
let sub = root.join("a/b");
std::fs::create_dir_all(&sub).unwrap();
let out = sc(&sub, &["serve", "fingerprint"]);
assert!(
out.status.success(),
"{}",
String::from_utf8_lossy(&out.stderr)
);
assert!(String::from_utf8_lossy(&out.stdout).starts_with("sha256:"));
assert!(
root.join(".sc/serve-tls").is_dir(),
"minted in the repo root"
);
assert!(!sub.join(".sc").exists(), "never in the subdirectory");

let bare =
std::env::temp_dir().join(format!("scl-cli-fingerprint-bare-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&bare);
std::fs::create_dir_all(&bare).unwrap();
let out = sc(&bare, &["serve", "fingerprint"]);
assert!(!out.status.success());
assert!(!bare.join(".sc").exists(), "nothing may be created");

std::fs::remove_dir_all(&root).unwrap();
std::fs::remove_dir_all(&bare).unwrap();
assert!(
!root.exists() && !bare.exists(),
"test must leave no residue"
);
}
Loading
Loading