T09 · Insecure Skill Coding Practices
- Location
scripts/schoolfit_api.py:661- Finding
SchoolFit Access Code May Be Disclosed Through Cross-Origin HTTP Redirects
- Content
View full analysis
Vulnerability Details
File Location:
scripts/schoolfit_api.py:661-686
Vulnerability Type: Credential exposure through unrestricted automatic redirects
Risk Level: HighVulnerable Code
python def request_json( method: str, base_url: str, path: str, *, params: dict[str, Any] | None = None, body: dict[str, Any] | None = None, skill_code: str | None = None, trace_id: TraceId | None = None, activation_status: ActivationMode = "reserved", skill_version: str | None = None, ) -> Any: url = make_url(base_url, path, params) data = None code = skill_code or SCHOOLFIT_SKILL_CLIENT_CODE headers = { "Accept": "application/json", "User-Agent": f"schoolfit-openclaw-skill/{SKILL_VERSION}", SKILL_CODE_HEADER: code, SKILL_VERSION_HEADER: skill_version or SKILL_VERSION_HEADER_VERSION, SKILL_ACTIVATION_STATUS_HEADER: activation_status, } if trace_id: headers[SKILL_TRACE_HEADER] = trace_id if body is not None: data = json.dumps(body, ensure_ascii=False).encode("utf-8") headers["Content-Type"] = "application/json" last_error: Exception | None = None for attempt in range(RETRIES + 1): req = urllib.request.Request(url, data=data, headers=headers, method=method) try: with urllib.request.urlopen(req, timeout=TIMEOUT_SECONDS) as resp:Technical Analysis
The
make_url()function validates the initial URL and restricts it to HTTPS requests underschoolfit.hk. However, the subsequent use ofurllib.request.urlopen()enables automatic redirect processing.The request includes the user-provided SchoolFit access code in the custom
X-SchoolFit-Skill-Codeheader. The implementation does not install a restrictive redirect handler, revalidate each redirect destination, or explicitly remove sensitive headers whe ...[truncated 1651 chars]- Remediation
View remediation
Remediation Suggestions
- Disable automatic redirects for credential-bearing API requests and handle redirect responses explicitly.
- If redirects are operationally required, validate every destination before following it:
- Require the
httpsscheme. - Require the normalized hostname to be exactly
schoolfit.hk. - Reject user information, custom ports, fragments, and unexpected paths.
- Limit the number of redirects.
- Require the
- Never forward
X-SchoolFit-Skill-Code,X-SchoolFit-Skill-Trace-Id, or other authorization-related headers when the origin changes. - Consider rejecting all cross-origin redirects rather than attempting to sanitize them.
- Add automated tests covering:
- Same-origin redirects.
- Cross-origin redirects.
- HTTPS-to-HTTP redirects.
- Redirect loops.
- Redirects containing user information or nonstandard ports.
- Verification that credential headers never reach a different origin.
- Prefer a narrowly configured HTTP client or custom
urllib.request.HTTPRedirectHandlerthat enforces these policies centrally.
