{"record":{"id":"e42289ed3fc83b39","repo":"jdx/mise","slug":"setup-repository-urls-must-not-contain-credentials","errorCode":null,"errorMessage":"setup repository URLs must not contain credentials, query parameters, or fragments; use a Git credential helper or SSH agent","messagePattern":"setup repository URLs must not contain credentials, query parameters, or fragments; use a Git credential helper or SSH agent","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/history/sync/network.rs","lineNumber":44,"sourceCode":"        .trim_start()\n        .get(..5)\n        .is_some_and(|prefix| prefix.eq_ignore_ascii_case(\"http:\"))\n        || value\n            .trim_start()\n            .get(..6)\n            .is_some_and(|prefix| prefix.eq_ignore_ascii_case(\"https:\"));\n    if http_like && url::Url::parse(value).is_err() {\n        bail!(\"invalid HTTP setup repository URL; use a Git credential helper for authentication\");\n    }\n    if let Ok(url) = url::Url::parse(value) {\n        let http = matches!(url.scheme(), \"http\" | \"https\");\n        if url.password().is_some()\n            || (http\n                && (!url.username().is_empty()\n                    || url.query().is_some()\n                    || url.fragment().is_some()))\n        {\n            bail!(\n                \"setup repository URLs must not contain credentials, query parameters, or fragments; use a Git credential helper or SSH agent\"\n            );\n        }\n    }\n    Ok(())\n}\n\n#[cfg(test)]\nmod tests {\n    use super::{HistoryRepo, PushOutcome, Remote, UPSTREAM_REF, validate_url};\n\n    #[test]\n    fn disposable_tip_probe_is_shallow_but_ordinary_fetch_keeps_ancestry() {\n        let temp = tempfile::tempdir().unwrap();\n        let source = HistoryRepo::open_or_init_in(&temp.path().join(\"source\"))\n            .unwrap()\n            .unwrap();\n        let tree = source.empty_object(\"tree\").unwrap();","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/history/sync/network.rs#L26-L62","documentation":"validate_url refuses repository URLs that contain a username/password, query string, or fragment. Credentials in persisted URLs leak into config, logs, and the history-health error records; query/fragment parts have no meaning for git remotes and usually indicate a malformed or hostile URL. The error directs users to git credential helpers or the SSH agent.","triggerScenarios":"validate_url (via fetch_with_depth, push, symbolic_head, ls_remote) receiving a parsed http(s) URL with a password set, or an http(s) URL with a nonempty username, query, or fragment — e.g. \"https://user:token@host/repo.git?ref=main#frag\".","commonSituations":"Pasting an access-token URL copied from a web UI (https://x-access-token:TOKEN@github.com/...); putting ?private_token= on a GitLab URL; a tracking/UTM fragment left in a copied URL.","solutions":["Remove the username:password portion from the URL and configure a git credential helper (git credential-store, helper, or manager) instead","Remove any ?query or #fragment from the URL","For token auth over HTTPS, use the credential helper or switch to an SSH remote with your agent"],"exampleFix":"# before\nremote = \"https://ci:ghp_xxx@github.com/org/repo.git?ref=main\"\n# after\nremote = \"https://github.com/org/repo.git\"\n# plus: git config --global credential.helper manager (or store token out of band)","handlingStrategy":"validation","validationCode":"const u = new URL(url);\nif (u.username || u.password || u.search || u.hash) {\n  throw new Error(\"remote URL must not contain credentials, query, or fragment\");\n}","typeGuard":"function isCredentialFreeUrl(v: string): boolean {\n  try {\n    const u = new URL(v);\n    return !u.username && !u.password && !u.search && !u.hash;\n  } catch { return false; }\n}","tryCatchPattern":"match validate_url(&value) {\n    Err(e) if e.to_string().contains(\"must not contain credentials\") => {\n        eprintln!(\"{e}; move the token into a credential helper\");\n        return Err(e);\n    }\n    other => other?,\n}","preventionTips":["Store tokens in git credential helpers or the SSH agent, never in remote URLs","Strip ?query/#fragment when copying URLs from web UIs","Scan configs in CI for URLs containing 'user:pass@' or '?token=' patterns"],"tags":["git","security","credentials","url"],"backgroundTag":"credentials-in-url","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}