T09 · Insecure Skill Coding Practices
- Location
scripts/risha_api.py:434- Finding
Reusable Authentication Tokens and Session Cookies Exposed Through Standard Output
- Content
View full analysis
int: client = RishaClient(base_url=args.base_url) payload = client.login() result = { "login_response": payload, "derived_authorization_header": client.session_header, "cookies": deepcopy(client.cookie_jar), } print(json_dump(result)) return 0 ``` Related authentication-header construction occurs at lines 251–258: ```python def get_auth_header(self) -> str | None: env_header = os.environ.get("RISHA_AUTH_HEADER") if env_header: return env_header.strip() if self.session_header: return self.session_header username = os.environ.get("RISHA_BASIC_USERNAME") password = os.environ.get("RISHA_BASIC_PASSWORD") if username and password: token = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("ascii") return f"Basic {token}" return None ``` ### Technical Analysis The `login` command deliberately prints three potentially sensitive objects: - The complete login response, which may contain tokens or account information. - The derived Bearer authorization header. - All session cookies captured from the login response. In an AI Agent environment, standard output can be returned to the model, retained in conversation history, stored in execution logs, or exposed to downstream tooling. Bearer tokens and session cookies are reusable authentication secrets and must not appear in normal command output. The Base64 operation at line 257 is conventional HTTP Basic authentication encoding and is not encryption. Although that encoded Basic credential is not directly printed by `command_login`, it remains sensitive because it is a reversible representation of the username and password. The directly conf ...[truncated 1773 chars]- Remediation
View remediation
int: client = RishaClient(base_url=args.base_url) client.login() print(json_dump({"authenticated": True})) return 0 ``` 2. Never print: - Authorization headers. - Access or refresh tokens. - Session cookies. - Raw login responses that have not been sanitized. - Base64-encoded Basic credentials. 3. Implement recursive response redaction before displaying any authentication-related payload. Redact keys such as: - `access` - `access_token` - `refresh` - `refresh_token` - `token` - `jwt` - `authorization` - `cookie` - `set-cookie` - `password` - `secret` 4. If troubleshooting requires confirmation of token extraction, print only non-sensitive metadata, such as whether a token or cookie was detected: ```json { "authenticated": true, "auth_method": "bearer", "session_cookie_received": true } ``` 5. Add automated tests that run the login-output formatter with synthetic tokens and cookies and assert that none of the secret values appear in stdout or stderr. 6. Document that Agent transcripts and tool output are not secure secret-storage channels. Require users to supply credentials through protected environment or secret-management facilities. ]]>
