T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/inject_and_run.sh:13
- Finding
- Reusable OAuth Credential Injected into Remote Colab Code<![CDATA[ ## Vulnerability Details **File Location**: `scripts/inject_and_run.sh:13-29` **Additional Locations**: `SKILL.md:56-69`, `references/examples.md:34-41` **Vulnerability Type**: Reusable OAuth credential exposure through remote source injection **Risk Level**: High ### Vulnerable Code ```bash TOKEN_B64=$(python3 -c " import base64, os with open(os.path.expanduser('~/.colab-mcp-auth-token.json')) as f: print(base64.b64encode(f.read().encode()).decode()) ") # Create temp script with token injected (restricted permissions) TMPSCRIPT=$(mktemp /tmp/colab_XXXXX.py) chmod 600 "$TMPSCRIPT" # Always clean up the token-bearing temp file cleanup() { rm -f "$TMPSCRIPT"; } trap cleanup EXIT INT TERM sed "s|__COLAB_TOKEN_PLACEHOLDER__|${TOKEN_B64}|" "$SCRIPT" > "$TMPSCRIPT" # Run on Colab SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" python3 "$SCRIPT_DIR/colab_run.py" exec --file "$TMPSCRIPT" "$@" ``` The documented remote-side usage decodes and writes the credential: ```python TOKEN_B64 = "__COLAB_TOKEN_PLACEHOLDER__" token_data = json.loads(base64.b64decode(TOKEN_B64)) with open('/tmp/token.json', 'w') as f: json.dump(token_data, f) creds = Credentials.from_authorized_user_file('/tmp/token.json') service = build('drive', 'v3', credentials=creds) ``` ### Technical Analysis The script reads the complete local `~/.colab-mcp-auth-token.json` file, Base64-encodes it, substitutes it into Python source code, and submits that source to a remote Google Colab runtime. Base64 is a transport encoding and provides no confidentiality. The credential file may include both access and refresh tokens. Consequently, the remote runtime receives a reusable account credential rather than a narrowly delegated, short-lived capability. The credential may also cover identity, Colab, and Drive scopes. This exceeds the minimum privilege needed when a remote task only needs to read or write a specific checkpoint. The local temporary script is assigned mode `0600` and remo ...[truncated 1636 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Do not embed refresh-token-bearing OAuth credential files in notebook source code. 2. Use short-lived, task-specific credentials that cannot be refreshed and are restricted to the minimum required resource and operation. 3. Prefer a brokered upload/download design where Drive operations remain local and only required files are transferred to the runtime. 4. If remote Drive access is unavoidable, use the supported Colab authentication workflow or a dedicated service identity with narrowly scoped permissions. 5. Separate Colab authorization from Drive authorization so a remote task does not receive unrelated account privileges. 6. Create any remote credential file with mode `0600`, avoid predictable locations, and delete it in a `finally` block immediately after credentials are loaded. 7. Prevent credentials from appearing in source, notebook history, kernel output, exceptions, logs, or diagnostic dumps. 8. Revoke and rotate any OAuth credentials that may already have been transmitted to untrusted runtimes. ]]>
