xuanzhu 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +424 -0
  3. package/bin/xzh.js +3 -0
  4. package/dist/cli.js +5602 -0
  5. package/dist/cli.js.map +7 -0
  6. package/dist/skills/aws/SKILL.md +70 -0
  7. package/dist/skills/datadog/SKILL.md +261 -0
  8. package/dist/skills/elasticsearch/SKILL.md +88 -0
  9. package/dist/skills/elasticsearch/install.sh +91 -0
  10. package/dist/skills/email/SKILL.md +63 -0
  11. package/dist/skills/github/SKILL.md +69 -0
  12. package/dist/skills/gitlab/SKILL.md +68 -0
  13. package/dist/skills/gitlab/install.sh +74 -0
  14. package/dist/skills/gmail/README.md +139 -0
  15. package/dist/skills/gmail/SECURITY.md +552 -0
  16. package/dist/skills/gmail/SETUP.md +258 -0
  17. package/dist/skills/gmail/activate-gmail-cli.sh +15 -0
  18. package/dist/skills/gmail/generate-hashes.sh +82 -0
  19. package/dist/skills/gmail/gmail-cli-secure.py +599 -0
  20. package/dist/skills/gmail/install.sh +313 -0
  21. package/dist/skills/gmail/requirements.txt +38 -0
  22. package/dist/skills/gmail/skill.md +225 -0
  23. package/dist/skills/jira/SKILL.md +68 -0
  24. package/dist/skills/kubernetes/SKILL.md +70 -0
  25. package/dist/skills/linear/SKILL.md +48 -0
  26. package/dist/skills/mongodb/SKILL.md +53 -0
  27. package/dist/skills/mysql/SKILL.md +71 -0
  28. package/dist/skills/mysql/install.sh +74 -0
  29. package/dist/skills/officecli/SKILL.md +429 -0
  30. package/dist/skills/playwright/SKILL.md +171 -0
  31. package/dist/skills/postgres/SKILL.md +44 -0
  32. package/dist/skills/postgres/install.sh +73 -0
  33. package/dist/skills/redis/SKILL.md +58 -0
  34. package/dist/skills/redis/install.sh +39 -0
  35. package/dist/skills/sentry/SKILL.md +59 -0
  36. package/dist/skills/telegram/SKILL.md +151 -0
  37. package/package.json +46 -0
@@ -0,0 +1,552 @@
1
+ # Gmail CLI Security Guide
2
+
3
+ This document provides comprehensive security guidance for the Gmail CLI tool.
4
+
5
+ ## 🎯 Security Overview
6
+
7
+ Gmail CLI handles sensitive credentials and accesses your Gmail account. Proper security measures are **critical** to protect:
8
+
9
+ - OAuth2 client credentials
10
+ - Access tokens with Gmail permissions
11
+ - Email content and metadata
12
+ - Personal and confidential communications
13
+
14
+ ## 🚨 Threat Model
15
+
16
+ ### Threats We Protect Against
17
+
18
+ 1. **Credential Theft**
19
+ - Other users on shared systems reading credential files
20
+ - Malware scanning filesystem for common credential paths
21
+ - Accidental commits to public repositories
22
+ - Unencrypted backups exposing credentials
23
+
24
+ 2. **Token Compromise**
25
+ - Stolen tokens used to access Gmail remotely
26
+ - Long-lived tokens persisting after password changes
27
+ - Token replay attacks
28
+
29
+ 3. **Privilege Escalation**
30
+ - Over-privileged OAuth scopes allowing more access than needed
31
+ - Compromised tool deleting or modifying emails
32
+
33
+ 4. **Supply Chain Attacks**
34
+ - Malicious Python packages
35
+ - Dependency confusion attacks
36
+ - Compromised package repositories
37
+
38
+ 5. **Input Injection**
39
+ - Command injection via email parameters
40
+ - Path traversal via attachment paths
41
+ - Email header injection
42
+
43
+ ### Threats Outside Our Scope
44
+
45
+ - Google account compromise (use 2FA, strong passwords)
46
+ - Network-level attacks (use TLS/HTTPS)
47
+ - Physical device theft (use full-disk encryption)
48
+ - Operating system vulnerabilities (keep OS updated)
49
+
50
+ ## 🔐 Security Requirements (MANDATORY)
51
+
52
+ ### 1. File Permissions
53
+
54
+ **CRITICAL**: Improper file permissions are the #1 vulnerability.
55
+
56
+ ```bash
57
+ # Secure the credential directory
58
+ chmod 700 ~/.gmail-cli/
59
+
60
+ # Secure all files in the directory
61
+ chmod 600 ~/.gmail-cli/*
62
+
63
+ # Verify permissions
64
+ ls -la ~/.gmail-cli/
65
+ # Expected: drwx------ (700) for directory
66
+ # Expected: -rw------- (600) for files
67
+ ```
68
+
69
+ **Why?** Default permissions (755/644) allow any user on the system to read your credentials and tokens.
70
+
71
+ **Shared Systems**: On university servers, shared hosting, or multi-user workstations, other users can trivially steal your credentials if permissions are wrong.
72
+
73
+ ### 2. OAuth2 Scope Minimization
74
+
75
+ **Use minimal required scopes:**
76
+
77
+ ```python
78
+ # ✅ RECOMMENDED - Minimal scopes
79
+ SCOPES = [
80
+ 'https://www.googleapis.com/auth/gmail.readonly', # Read emails
81
+ 'https://www.googleapis.com/auth/gmail.send', # Send emails
82
+ ]
83
+
84
+ # ⚠️ ACCEPTABLE - If you need labels
85
+ SCOPES = [
86
+ 'https://www.googleapis.com/auth/gmail.readonly',
87
+ 'https://www.googleapis.com/auth/gmail.send',
88
+ 'https://www.googleapis.com/auth/gmail.labels', # Manage labels
89
+ ]
90
+
91
+ # ❌ AVOID - Too permissive
92
+ SCOPES = [
93
+ 'https://www.googleapis.com/auth/gmail.modify', # Full access including DELETE
94
+ ]
95
+ ```
96
+
97
+ **Scope comparison:**
98
+
99
+ | Scope | Read | Send | Labels | Delete | Modify |
100
+ |-------|------|------|--------|--------|--------|
101
+ | `gmail.readonly` | ✅ | ❌ | ❌ | ❌ | ❌ |
102
+ | `gmail.send` | ❌ | ✅ | ❌ | ❌ | ❌ |
103
+ | `gmail.labels` | ❌ | ❌ | ✅ | ❌ | ❌ |
104
+ | `gmail.modify` | ✅ | ✅ | ✅ | ✅ | ✅ |
105
+
106
+ **Why?** If the tool or your device is compromised, minimal scopes limit the damage an attacker can do.
107
+
108
+ ### 3. Virtual Environment Isolation
109
+
110
+ **Always use virtual environments:**
111
+
112
+ ```bash
113
+ # Install in virtual environment (done by install.sh)
114
+ python3 -m venv .venv-gmail-cli
115
+ source .venv-gmail-cli/bin/activate
116
+ pip install -r requirements.txt
117
+
118
+ # Use the wrapper script that activates venv automatically
119
+ ./.codebuddy/bin/gmail-cli-wrapper list --max 10
120
+ ```
121
+
122
+ **Why?**
123
+ - Prevents global package pollution
124
+ - Isolates dependencies from system Python
125
+ - Easier to audit and track installed packages
126
+ - Reduces attack surface
127
+
128
+ ### 4. Dependency Integrity
129
+
130
+ **Pin versions and verify hashes:**
131
+
132
+ ```bash
133
+ # Generate hashes for requirements.txt
134
+ pip hash google-api-python-client==2.108.0
135
+
136
+ # Install with hash verification
137
+ pip install --require-hashes -r requirements.txt
138
+ ```
139
+
140
+ **Regular security audits:**
141
+
142
+ ```bash
143
+ # Check for known vulnerabilities
144
+ pip-audit
145
+
146
+ # Check outdated packages
147
+ pip list --outdated
148
+ ```
149
+
150
+ **Why?** Prevents supply chain attacks where malicious code is injected into legitimate packages.
151
+
152
+ ### 5. Input Validation
153
+
154
+ **Never trust user input:**
155
+
156
+ ```python
157
+ # ✅ GOOD - Validate email addresses
158
+ def validate_email(email: str) -> str:
159
+ pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
160
+ if not re.match(pattern, email):
161
+ raise ValueError(f"Invalid email: {email}")
162
+ if '\n' in email or '\r' in email:
163
+ raise ValueError("Email contains invalid characters")
164
+ return email
165
+
166
+ # ✅ GOOD - Validate file paths
167
+ def validate_attachment(path: str) -> Path:
168
+ p = Path(path).resolve()
169
+ if not p.is_file():
170
+ raise ValueError(f"File not found: {path}")
171
+ if not os.access(p, os.R_OK):
172
+ raise ValueError(f"File not readable: {path}")
173
+ # Prevent access to sensitive system files
174
+ if str(p).startswith(('/etc/', '/sys/', '/proc/')):
175
+ raise ValueError(f"Access denied: {path}")
176
+ return p
177
+
178
+ # ❌ BAD - No validation
179
+ def send_email(to, subject, body, attach):
180
+ # Directly using user input - DANGEROUS!
181
+ os.system(f"mail -s '{subject}' {to} < {attach}") # Command injection!
182
+ ```
183
+
184
+ ### 6. Token Management
185
+
186
+ **Token lifecycle:**
187
+
188
+ - Tokens auto-refresh every 7 days
189
+ - Force re-authentication after 30 days (security hygiene)
190
+ - Revoke tokens immediately if device is lost/stolen
191
+
192
+ **Token revocation:**
193
+
194
+ ```bash
195
+ # Via CLI (if implemented)
196
+ gmail-cli token --revoke
197
+
198
+ # Via Google Account Settings
199
+ # Visit: https://myaccount.google.com/permissions
200
+ # Find "Gmail CLI" and click "Remove Access"
201
+ ```
202
+
203
+ **When to revoke:**
204
+ - 🚨 Device lost or stolen
205
+ - 🚨 Suspected compromise
206
+ - 🚨 Leaving organization/changing roles
207
+ - 🚨 No longer need access
208
+ - ⚠️ Every 90 days as good practice
209
+
210
+ ## 🛡️ Defense in Depth
211
+
212
+ Security is layered. Implement multiple controls:
213
+
214
+ ### Layer 1: Operating System Security
215
+
216
+ ```bash
217
+ # Enable full-disk encryption
218
+ # macOS: FileVault
219
+ # Windows: BitLocker
220
+ # Linux: LUKS
221
+
222
+ # Keep OS updated
223
+ sudo apt update && sudo apt upgrade # Debian/Ubuntu
224
+ brew upgrade # macOS
225
+ ```
226
+
227
+ ### Layer 2: Filesystem Security
228
+
229
+ ```bash
230
+ # Secure file permissions (done automatically by install.sh)
231
+ chmod 700 ~/.gmail-cli/
232
+ chmod 600 ~/.gmail-cli/*
233
+
234
+ # Use encrypted home directory (optional, advanced)
235
+ # Ubuntu: ecryptfs-setup-private
236
+ ```
237
+
238
+ ### Layer 3: Application Security
239
+
240
+ ```bash
241
+ # Virtual environment isolation
242
+ python3 -m venv .venv-gmail-cli
243
+
244
+ # Pinned dependencies with hash verification
245
+ pip install --require-hashes -r requirements.txt
246
+
247
+ # Regular security audits
248
+ pip-audit
249
+ ```
250
+
251
+ ### Layer 4: Network Security
252
+
253
+ ```bash
254
+ # Gmail API uses HTTPS (TLS 1.2+) by default
255
+ # No additional configuration needed
256
+
257
+ # For enhanced security, use VPN when on untrusted networks
258
+ ```
259
+
260
+ ### Layer 5: Credential Security
261
+
262
+ ```bash
263
+ # Option 1: OS keyring (recommended for desktop)
264
+ # Use macOS Keychain, Windows Credential Manager, or gnome-keyring
265
+
266
+ # Option 2: Encrypted credential files
267
+ # Encrypt credentials.json and token.pickle with strong password
268
+
269
+ # Option 3: Hardware security keys (advanced)
270
+ # Use TPM, Secure Enclave, or YubiKey for credential storage
271
+ ```
272
+
273
+ ## 🔍 Security Auditing
274
+
275
+ ### Pre-Flight Security Check
276
+
277
+ Run before each use:
278
+
279
+ ```bash
280
+ #!/bin/bash
281
+ # security-check.sh
282
+
283
+ echo "🔍 Gmail CLI Security Audit"
284
+ echo "=========================="
285
+
286
+ GMAIL_DIR="$HOME/.gmail-cli"
287
+ ISSUES=0
288
+
289
+ # Check directory permissions
290
+ DIR_PERMS=$(stat -c %a "$GMAIL_DIR" 2>/dev/null || stat -f %A "$GMAIL_DIR" 2>/dev/null)
291
+ if [ "$DIR_PERMS" != "700" ]; then
292
+ echo "❌ Directory permissions insecure: $DIR_PERMS (should be 700)"
293
+ ((ISSUES++))
294
+ else
295
+ echo "✅ Directory permissions secure"
296
+ fi
297
+
298
+ # Check credential file permissions
299
+ for file in credentials.json token.pickle; do
300
+ if [ -f "$GMAIL_DIR/$file" ]; then
301
+ PERMS=$(stat -c %a "$GMAIL_DIR/$file" 2>/dev/null || stat -f %A "$GMAIL_DIR/$file" 2>/dev/null)
302
+ if [ "$PERMS" != "600" ]; then
303
+ echo "❌ $file permissions insecure: $PERMS (should be 600)"
304
+ ((ISSUES++))
305
+ else
306
+ echo "✅ $file permissions secure"
307
+ fi
308
+ fi
309
+ done
310
+
311
+ # Check for credentials in git
312
+ if git rev-parse --git-dir > /dev/null 2>&1; then
313
+ if git ls-files | grep -q "credentials.json\|token.pickle"; then
314
+ echo "❌ CRITICAL: Credentials tracked in git!"
315
+ ((ISSUES++))
316
+ else
317
+ echo "✅ No credentials in git"
318
+ fi
319
+ fi
320
+
321
+ # Check token age
322
+ if [ -f "$GMAIL_DIR/token.pickle" ]; then
323
+ TOKEN_AGE=$(($(date +%s) - $(stat -c %Y "$GMAIL_DIR/token.pickle" 2>/dev/null || stat -f %m "$GMAIL_DIR/token.pickle")))
324
+ TOKEN_DAYS=$((TOKEN_AGE / 86400))
325
+
326
+ if [ $TOKEN_DAYS -gt 90 ]; then
327
+ echo "⚠️ Token is $TOKEN_DAYS days old (recommend rotation)"
328
+ ((ISSUES++))
329
+ else
330
+ echo "✅ Token age acceptable ($TOKEN_DAYS days)"
331
+ fi
332
+ fi
333
+
334
+ # Check Python package vulnerabilities
335
+ if command -v pip-audit &> /dev/null; then
336
+ echo "🔍 Checking for vulnerable dependencies..."
337
+ if pip-audit --quiet; then
338
+ echo "✅ No known vulnerabilities in dependencies"
339
+ else
340
+ echo "❌ Vulnerable dependencies found (run 'pip-audit' for details)"
341
+ ((ISSUES++))
342
+ fi
343
+ fi
344
+
345
+ echo ""
346
+ if [ $ISSUES -eq 0 ]; then
347
+ echo "✅ Security check passed!"
348
+ exit 0
349
+ else
350
+ echo "❌ Found $ISSUES security issue(s). Review and fix before using Gmail CLI."
351
+ exit 1
352
+ fi
353
+ ```
354
+
355
+ ### Regular Maintenance
356
+
357
+ **Weekly:**
358
+ - Review access logs (if implemented)
359
+ - Check for unusual email activity
360
+
361
+ **Monthly:**
362
+ - Run `pip-audit` to check for vulnerabilities
363
+ - Update dependencies if security patches available
364
+ - Review and rotate tokens
365
+
366
+ **Quarterly:**
367
+ - Audit OAuth2 permissions: https://myaccount.google.com/permissions
368
+ - Review all authorized applications
369
+ - Revoke unused access
370
+
371
+ ## 🚫 Common Security Mistakes
372
+
373
+ ### ❌ Mistake 1: Committing Secrets to Git
374
+
375
+ ```bash
376
+ # BAD - Credentials in repo
377
+ git add ~/.gmail-cli/credentials.json
378
+ git commit -m "Add Gmail credentials" # NEVER DO THIS!
379
+
380
+ # GOOD - Use .gitignore
381
+ echo "credentials.json" >> .gitignore
382
+ echo "token.pickle" >> .gitignore
383
+ ```
384
+
385
+ **If you've already committed secrets:**
386
+
387
+ ```bash
388
+ # Remove from git history
389
+ git filter-branch --force --index-filter \
390
+ "git rm --cached --ignore-unmatch .gmail-cli/credentials.json" \
391
+ --prune-empty --tag-name-filter cat -- --all
392
+
393
+ # Or use BFG Repo-Cleaner (faster)
394
+ bfg --delete-files credentials.json
395
+
396
+ # Force push (WARNING: rewrites history)
397
+ git push origin --force --all
398
+
399
+ # THEN: Revoke the exposed credentials immediately!
400
+ # 1. Delete OAuth2 client in Google Cloud Console
401
+ # 2. Create new credentials
402
+ # 3. Re-authenticate
403
+ ```
404
+
405
+ ### ❌ Mistake 2: World-Readable Permissions
406
+
407
+ ```bash
408
+ # BAD - Anyone can read
409
+ chmod 755 ~/.gmail-cli/
410
+ chmod 644 ~/.gmail-cli/credentials.json
411
+
412
+ # GOOD - Only you can read
413
+ chmod 700 ~/.gmail-cli/
414
+ chmod 600 ~/.gmail-cli/credentials.json
415
+ ```
416
+
417
+ ### ❌ Mistake 3: Using Global pip Install
418
+
419
+ ```bash
420
+ # BAD - Installs globally, can affect other apps
421
+ sudo pip install google-api-python-client
422
+
423
+ # GOOD - Isolated virtual environment
424
+ python3 -m venv .venv
425
+ source .venv/bin/activate
426
+ pip install google-api-python-client
427
+ ```
428
+
429
+ ### ❌ Mistake 4: Not Validating Input
430
+
431
+ ```python
432
+ # BAD - Command injection vulnerability
433
+ subject = input("Subject: ")
434
+ os.system(f"gmail-cli send --subject '{subject}'")
435
+ # User input: '; rm -rf ~/*
436
+
437
+ # GOOD - Use subprocess with list (no shell)
438
+ import subprocess
439
+ subject = input("Subject: ")
440
+ subprocess.run(['gmail-cli', 'send', '--subject', subject])
441
+ ```
442
+
443
+ ### ❌ Mistake 5: Ignoring Security Warnings
444
+
445
+ ```bash
446
+ # BAD - Ignoring pip-audit warnings
447
+ pip-audit
448
+ # Found vulnerabilities: google-auth-oauthlib==1.0.0 (CVE-2023-12345)
449
+ # ... (ignores and continues using vulnerable version)
450
+
451
+ # GOOD - Address security warnings immediately
452
+ pip-audit
453
+ # Found vulnerabilities: google-auth-oauthlib==1.0.0 (CVE-2023-12345)
454
+ pip install --upgrade google-auth-oauthlib
455
+ pip-audit # Verify fixed
456
+ ```
457
+
458
+ ## 📚 Additional Resources
459
+
460
+ ### Security Standards & Guidelines
461
+
462
+ - [OWASP Top 10](https://owasp.org/www-project-top-ten/)
463
+ - [CWE Top 25 Most Dangerous Software Weaknesses](https://cwe.mitre.org/top25/)
464
+ - [Google OAuth2 Best Practices](https://developers.google.com/identity/protocols/oauth2/production-readiness)
465
+ - [NIST Cybersecurity Framework](https://www.nist.gov/cyberframework)
466
+
467
+ ### Tools
468
+
469
+ - `pip-audit` - Check for known vulnerabilities in Python packages
470
+ - `safety` - Alternative to pip-audit
471
+ - `bandit` - Security linter for Python code
472
+ - `gitleaks` - Scan git repos for secrets
473
+ - `truffleHog` - Find secrets in git history
474
+
475
+ ### Incident Response
476
+
477
+ **If credentials are compromised:**
478
+
479
+ 1. **Immediate Actions** (within minutes):
480
+ - Revoke OAuth2 token: https://myaccount.google.com/permissions
481
+ - Change Google account password
482
+ - Enable 2FA if not already enabled
483
+ - Delete local credentials: `rm -rf ~/.gmail-cli/`
484
+
485
+ 2. **Investigation** (within hours):
486
+ - Check Gmail "Last account activity" for suspicious logins
487
+ - Review sent emails for unauthorized messages
488
+ - Check email filters for forwarding rules
489
+ - Review OAuth2 clients in Google Cloud Console
490
+
491
+ 3. **Remediation** (within days):
492
+ - Delete compromised OAuth2 client in Google Cloud Console
493
+ - Create new OAuth2 credentials with new client secret
494
+ - Re-install Gmail CLI with new credentials
495
+ - Review and improve security measures
496
+ - Document incident and lessons learned
497
+
498
+ 4. **Prevention** (ongoing):
499
+ - Implement additional security controls
500
+ - Regular security audits
501
+ - Security training
502
+ - Incident response drills
503
+
504
+ ### Support & Reporting
505
+
506
+ **Security Vulnerabilities:**
507
+
508
+ If you discover a security vulnerability in Gmail CLI:
509
+
510
+ 1. **DO NOT** open a public GitHub issue
511
+ 2. Email security details to: [your-security-email@example.com]
512
+ 3. Include:
513
+ - Description of vulnerability
514
+ - Steps to reproduce
515
+ - Potential impact
516
+ - Suggested fix (if any)
517
+
518
+ **Expected Response:**
519
+ - Acknowledgment within 48 hours
520
+ - Preliminary assessment within 1 week
521
+ - Fix within 30 days (depending on severity)
522
+
523
+ ## ✅ Security Checklist
524
+
525
+ Before using Gmail CLI in production:
526
+
527
+ - [ ] Reviewed and understood threat model
528
+ - [ ] File permissions set correctly (700/600)
529
+ - [ ] Using minimal OAuth2 scopes (not `gmail.modify`)
530
+ - [ ] Dependencies installed in virtual environment
531
+ - [ ] `requirements.txt` uses pinned versions
532
+ - [ ] `.gitignore` configured to exclude secrets
533
+ - [ ] Full-disk encryption enabled
534
+ - [ ] Security audit script passes
535
+ - [ ] `pip-audit` shows no vulnerabilities
536
+ - [ ] Token rotation policy defined
537
+ - [ ] Incident response plan documented
538
+ - [ ] Team trained on security best practices
539
+ - [ ] Regular security audits scheduled
540
+
541
+ ## 📖 Version History
542
+
543
+ - **v1.0** (2024-01) - Initial security guidelines
544
+ - File permission requirements
545
+ - OAuth2 scope minimization
546
+ - Virtual environment isolation
547
+ - Input validation guidelines
548
+ - Token management policies
549
+
550
+ ---
551
+
552
+ **Remember**: Security is not a one-time setup, it's an ongoing process. Regularly review and update your security measures!