Commit e8c2db6
security: Fix overly permissive file modes and cache directory boundary
Four issues identified during code review and resolved:
1. World-writable directory creation during archive extraction —
pkg/archive/extract_targz.go, pkg/archive/extract_zip.go
Directories unpacked from archives were created with mode 0o777
(world-writable). Changed to 0o755 to match the principle of least
privilege applied elsewhere in the codebase.
2. World-writable file creation during zip extraction —
pkg/archive/extract_zip.go
Files extracted from .zip archives were created with a hardcoded
mode of 0o777. The .tar.gz extractor already did the right thing
by using os.FileMode(th.Mode) to preserve the permission bits from
the archive header. The .zip extractor now does the same via
z.Mode(). Hugo release zips built by goreleaser carry Unix
permission metadata, so the Hugo binary emerges executable (0o755)
rather than world-writable.
3. World-writable parent directory creation in helpers —
pkg/helpers/helpers.go
CopyFile used 0o777 when creating parent directories for the
destination. Changed to 0o755.
4. Incorrect directory boundary in cache size calculation —
pkg/cache/cache.go, pkg/cache/cache_test.go
Size() excluded files whose path had excludeDir as a string prefix,
meaning a directory named e.g. 'default123' would be silently
excluded alongside 'default'. Changed to an exact match check:
path != excludeDir && !strings.HasPrefix(path, excludeDir+"/")
The accompanying test was asserting the buggy behaviour (with a
comment claiming it was intentional); it now asserts the correct
behaviour.
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 9c8b192 commit e8c2db6
5 files changed
Lines changed: 11 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
59 | | - | |
60 | | - | |
61 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
0 commit comments