T09 · Insecure Skill Coding Practices
- Location
scripts/publish_to_wiki.py:48- Finding
Unvalidated Wiki Endpoint Can Expose Bearer Credentials and Published Content
- Content
View full analysis
dict: response = requests.post( wiki_url, headers={ "Content-Type": "application/json", "Authorization": f"Bearer {wiki_key}" }, data=payload ) return response.json() ``` ### Technical Analysis The script obtains `WIKI_URL` from an environment variable and uses it directly as the destination of an authenticated HTTP request. It does not parse or validate the URL, require HTTPS, restrict the destination hostname, or reject URL user information and unexpected schemes. Every request includes the Wiki.js API token in an `Authorization: Bearer` header. Publishing requests also include the complete Markdown document, title, description, tags, and destination path. If `WIKI_URL` is configured with an `http://` URL, these values may be intercepted or modified in transit. If an attacker can influence the environment variable or induce a configuration error, the credential and content can be sent directly to an attacker-controlled server. Network access and use of the Wiki.js token are necessary for the declared publishing functionality. The risk arises because the implementation permits a broader se ...[truncated 2104 chars]- Remediation
View remediation
str: parsed = urlparse(wiki_url) if parsed.scheme != "https": raise ValueError("WIKI_URL must use HTTPS") if not parsed.hostname or parsed.username or parsed.password: raise ValueError("WIKI_URL is malformed or contains user information") if allowed_hosts and parsed.hostname not in allowed_hosts: raise ValueError("WIKI_URL hostname is not approved") return wiki_url def _post(wiki_url: str, wiki_key: str, payload: str) -> dict: validated_url = validate_wiki_url(wiki_url) response = requests.post( validated_url, headers={ "Content-Type": "application/json", "Authorization": f"Bearer {wiki_key}", }, data=payload, timeout=(5, 30), ) response.raise_for_status() return ...[truncated 23 chars]
