Commit 6ee1d11
fix: Resolve GitHub Actions workflow failures, URL normalization, and security enhancements
This commit fixes multiple critical issues and adds defense-in-depth security improvements:
## Root Causes Fixed
1. **Manifest Structure Bug** (docs/docs_manifest.json)
- Fixed manifest "files" field being a list instead of dict
- This was causing "'list' object has no attribute 'get'" errors
- Converted to proper dict structure with metadata for each file
2. **URL Normalization** (scripts/fetch_claude_docs.py)
- Added normalize_url_to_legacy_format() function
- Handles new code.claude.com URL structure (/docs/en/hooks)
- Maintains legacy naming convention (en__docs__claude-code__hooks.md)
- Ensures consistent file naming across domain changes
3. **GitHub Actions Error Handler** (.github/workflows/update-docs.yml)
- Removed issue creation step (Issues disabled in this fork)
- Replaced with simple warning log and exit 1
- Removed unnecessary issues: write permission
## Security Enhancements (Defense-in-Depth)
4. **Input Sanitization** (scripts/fetch_claude_docs.py)
- Enhanced url_to_safe_filename() with whitelist-based character filtering
- Only allows: alphanumeric, hyphens, underscores, and dots
- Prevents path traversal attacks (../, etc/passwd)
- Blocks command injection (backticks, semicolons)
- Removes shell metacharacters and special characters
- Validates non-empty output after sanitization
5. **Shell Escaping** (.github/workflows/update-docs.yml, validate.yml)
- Implemented GitHub Actions heredoc format for commit messages
- Added proper variable quoting with ${VAR} syntax
- Used environment variables to prevent shell interpretation
- Applied UTC date formatting for consistency
- Added set -euo pipefail for strict error handling
6. **Security Testing** (tests/unit/test_fetch_claude_docs.py)
- Added 13 comprehensive security test cases:
* XSS injection attempts (<script> tags)
* Path traversal patterns (../../etc/passwd)
* Null byte injection (\x00)
* Shell metacharacters (;, |, &)
* Unicode control characters (right-to-left override)
* SQL injection patterns ('; DROP TABLE)
* Command injection (backticks)
* Windows reserved characters (<>:"|?*)
* Empty input validation
7. **Documentation** (README.md)
- Added comprehensive Security Notes section
- Documented defense-in-depth approach
- Highlighted input sanitization and testing coverage
- Referenced 99.7% test pass rate and 81% code coverage
## Technical Details
**URL Normalization Flow:**
- Input: /docs/en/hooks (new sitemap structure)
- Fetch URL: https://code.claude.com/docs/en/hooks.md
- Filename: en__docs__claude-code__hooks.md (legacy convention)
**Manifest Fix:**
- Before: {"files": ["file1.md", "file2.md"]}
- After: {"files": {"file1.md": {"hash": "...", "last_updated": "..."}}}
**Security Whitelist:**
- Allowed characters: [a-zA-Z0-9_.-]
- Prevents: Path traversal, command injection, XSS, SQL injection
- Validation: Rejects empty filenames after sanitization
## Testing
- ✅ All 575 tests passing (2 intentional skips)
- ✅ 81.28% code coverage (exceeds 81% target)
- ✅ 13 new security tests covering attack vectors
- ✅ Successfully fetched all 45 docs (44 pages + changelog)
- ✅ Correct file naming convention maintained
- ✅ GitHub workflow logic verified
- ✅ Zero test failures
## Impact
- Automated documentation updates will now work correctly
- File naming convention preserved across URL structure changes
- No more workflow failures from issue creation attempts
- Defense-in-depth security prevents injection attacks
- Comprehensive test coverage validates security hardening
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 41a22b1 commit 6ee1d11
6 files changed
Lines changed: 504 additions & 96 deletions
File tree
- .github/workflows
- docs
- scripts
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
| |||
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
65 | 67 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
69 | 71 | | |
70 | | - | |
71 | | - | |
72 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
73 | 75 | | |
74 | | - | |
75 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
76 | 84 | | |
77 | 85 | | |
78 | 86 | | |
| 87 | + | |
| 88 | + | |
79 | 89 | | |
80 | 90 | | |
81 | 91 | | |
82 | 92 | | |
83 | | - | |
| 93 | + | |
| 94 | + | |
84 | 95 | | |
85 | | - | |
86 | | - | |
| 96 | + | |
| 97 | + | |
87 | 98 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | | - | |
41 | | - | |
42 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
43 | 51 | | |
44 | 52 | | |
45 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
204 | 215 | | |
205 | 216 | | |
206 | 217 | | |
| |||
210 | 221 | | |
211 | 222 | | |
212 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
213 | 228 | | |
214 | 229 | | |
215 | 230 | | |
| |||
0 commit comments