T09 · Insecure Skill Coding Practices
- Location
scripts/gmail_no_send/auth.py:30- Finding
OAuth Credentials and Audit Logs Are Stored Without Enforced Restrictive Permissions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/gmail_no_send/auth.py:30-32;scripts/gmail_no_send/utils.py:18-30
Vulnerability Type: Insecure local storage of sensitive credentials and audit metadata
Risk Level: MediumVulnerable Code
scripts/gmail_no_send/auth.py:30-32:python def save_credentials(creds: Credentials): ensure_config_dir() token_path().write_text(creds.to_json())scripts/gmail_no_send/utils.py:18-30:python def ensure_config_dir(): config_dir().mkdir(parents=True, exist_ok=True) def audit_log(action: str, payload: dict | None = None): ensure_config_dir() entry = { "ts": int(time.time()), "action": action, "payload": payload or {}, } with audit_log_path().open("a", encoding="utf-8") as f: f.write(json.dumps(entry) + "\n")Technical Analysis
The application writes a refresh-capable OAuth token to
token.jsonusingPath.write_text()and appends operational metadata toaudit.logusing the default filesystem creation mode. It also creates the configuration directory without explicitly applying mode0700.Effective permissions therefore depend on the process umask and any pre-existing directory or files. Under a permissive environment, another local account or process may be able to read these files. The token is particularly sensitive because its scopes include Gmail read, modify, and compose authorization. Although this application has no send endpoint, a party that obtains the token can reuse it directly with the Gmail API, where the compose scope can permit sending.
The audit log can contain account labels, Gmail search queries, recipient addresses, message subjects, message IDs, and draft IDs. Exposure may reveal sensitive correspondence metadata even when the OAuth token itself is not compromised.
The documented threat model recommends applying
chmod 600to the token ...[truncated 1649 chars]- Remediation
View remediation
Remediation Suggestions
- Create the configuration directory with mode
0700and verify its owner and permissions before every use. - Create OAuth token and audit files with mode
0600, rather than relying on the process umask. - Write credentials atomically to a newly created private file, flush and synchronize it, and then replace the destination.
- Reject symbolic links and files not owned by the current user to reduce symlink and pre-created-file attacks.
- Validate permissions and ownership when loading an existing token; fail closed if the path is unsafe.
- Consider storing OAuth credentials in an operating-system credential manager or encrypted secret store.
- Minimize sensitive audit fields. Hash, redact, or omit search queries, recipient addresses, and message subjects where they are not required.
- Provide documented token revocation and rotation procedures for suspected exposure.
- Add automated tests verifying directory mode
0700, file mode0600, ownership validation, and rejection of symlinked paths.
- Create the configuration directory with mode
