T09 · Insecure Skill Coding Practices
- Location
scripts/exchange_link_builder.py:150- Finding
Vipshop Access Token Is Reversibly Embedded in Displayed Product Links
- Content
View full analysis
str: token_file = Path.home() / ".vipshop-user-login" / "tokens.json" if not token_file.exists(): return "" try: with open(token_file, 'r', encoding='utf-8') as f: data = json.load(f) if data and isinstance(data, dict) and 'cookies' in data: expires_at = data.get('expires_at') if expires_at and time.time() > expires_at: return "" cookies = data.get('cookies', {}) token = cookies.get("PASSPORT_ACCESS_TOKEN", "") if token: return token else: return "" else: return "" except json.JSONDecodeError: return "" except Exception: return "" ``` ```python # 获取 token token = _get_token() if not token: log("⚠️ token 为空,直接返回原始目标 URL") return target_url # 获取 secret key secret = _get_secret() # 构造数据对象 timestamp = int(time.time() * 1000) data_obj = {"t": token, "ts": timestamp} # 转换为 JSON 字符串 json_str = json.dumps(data_obj, separators=(",", ":")) # Base64 编码 base64_str = base64.b64encode(json_str.encode("utf-8")).decode("utf-8") # 生成签名 signature = _generate_signature(base64_str, secret) # 构造完整链接 base_url = "https://passport.vip.com/exchangeTokenFromApp" full_url = ( f"{base_url}?" f"dt={urllib.parse.quote(base64_str)}&" f"sg={signature}&" f"src={urllib.parse.quote(target_url)}" ) return full_url ``` ```python # 使用 build_product_link 生成带 exchange token 的链接 product_link = build_product_link( product.get('brandId', ''), product.get('productId', '') ) product_info = { "商品ID": product.get('productId', ''), "商品名称": product.get('title', ...[truncated 2893 chars]- Remediation
View remediation
-.html ``` 3. If authenticated token exchange is essential, perform it through a trusted server-side component that: - Keeps the access token and signing key out of client-visible data. - Returns only a short-lived, one-time, opaque identifier. - Binds the identifier to the intended destination and user. - Prevents replay and expires it within a minimal period. 4. Redact credential-bearing query parameters from logs, errors, analytics, and agent output. 5. Revoke or rotate access tokens that may already have been exposed through generated links. 6. Remove the duplicate credential read from link generation and pass only the minimum non-sensitive product identifiers required to build a link. 7. Add automated tests that decode all generated query parameters and fail if authentication tokens, cookies, or other secrets are present. ]]>
