BigPizzaV3/CodexPlusPlus · error · anyhow::Error

分享链接缺少解密密钥

Error message

分享链接缺少解密密钥

What it means

validate_share_url requires the URL to carry a fragment; the AES key for the encrypted payload is passed only in the fragment (k=...). A share link without a fragment cannot be decrypted, so it is rejected before any network request.

Solutions

  1. Copy the complete share link including the #k= fragment from the share dialog
  2. Re-share the session to generate a fresh link with its key
  3. Avoid link-shorteners or sanitizers that drop URL fragments

Example fix

// before
let url = "https://share.codexpp.cc/s/abc"; // missing fragment
// after
let url = "https://share.codexpp.cc/s/abc#k=AbCdEf..."; // full link with key
Defensive patterns

Strategy: validation

Validate before calling

fn share_url_has_key(url: &str) -> bool {
    reqwest::Url::parse(url.trim()).map(|u| u.fragment().is_some()).unwrap_or(false)
}

Prevention

When it happens

Trigger: Calling one of the share-import functions with a share URL missing its #k=... fragment — often the fragment is stripped when copying/pasting the link.

Common situations: Sharing only the base URL without the key fragment; chat apps or URL sanitizers stripping fragments; the user manually trimming the "#..." part of the link.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/12c2a0a8e6b79edb. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/session_share.rs:113

                .split('&')
                .find_map(|pair| pair.strip_prefix("k="))
        })
        .context("分享链接缺少解密密钥")?;
    let plaintext = decrypt_shared_payload(encrypted, key_value)?;
    let payload: Value = serde_json::from_slice(&plaintext).context("分享会话内容格式无效")?;
    if payload.get("kind").and_then(Value::as_str) != Some("codex-rollout") {
        bail!("当前分享内容不是可导入的 Codex rollout 会话");
    }
    import_rollout(home, &payload)
}

fn validate_share_url(url: &str) -> anyhow::Result<reqwest::Url> {
    let parsed = reqwest::Url::parse(url.trim()).context("分享 URL 格式无效")?;
    if parsed.scheme() != "https" || !parsed.host_str().is_some_and(|host| SHARE_HOSTS.contains(&host)) {
        bail!("仅支持 Codex++ 分享站点链接");
    }
    if parsed.fragment().is_none() {
        bail!("分享链接缺少解密密钥");
    }
    Ok(parsed)
}

fn decrypt_shared_payload(encrypted: &Value, key_value: &str) -> anyhow::Result<Vec<u8>> {
    if encrypted.get("v").and_then(Value::as_u64) != Some(1) {
        bail!("不支持此分享的数据格式");
    }
    let decode = |field: &str| -> anyhow::Result<Vec<u8>> {
        let value = encrypted
            .get(field)
            .and_then(Value::as_str)
            .with_context(|| format!("分享数据缺少 {field}"))?;
        base64::engine::general_purpose::URL_SAFE_NO_PAD
            .decode(value)
            .with_context(|| format!("分享数据 {field} 无效"))
    };
    let key = base64::engine::general_purpose::URL_SAFE_NO_PAD

View on GitHub (pinned to b1ed92e5e4)