Commit 3c14ede
Add cross-platform secure file permissions with Windows DACL support (#73)
# Problem
Unix permission modes (0600, 0700) used throughout the codebase are
no-ops on Windows for access control. On a multi-user Windows machine,
OAuth tokens, emails, and attachments are readable by other users.
# Solution
Create internal/fileutil/ package with build-tagged implementations:
- Unix: thin wrappers around os.WriteFile, os.MkdirAll, os.Chmod,
os.OpenFile
- Windows: after calling the standard os function, set a DACL
restricting access to the current user when the mode is owner-only (perm
& 0077 == 0)
# internal/fileutil/
- secure_unix.go (//go:build !windows) — thin wrappers around
os.WriteFile, os.MkdirAll, os.Chmod, os.OpenFile
- secure_windows.go (//go:build windows) — calls the standard os
function, then for owner-only modes (perm & 0077 == 0) applies a DACL
via golang.org/x/sys/windows that grants GENERIC_ALL only to the current
user with PROTECTED_DACL_SECURITY_INFORMATION to block inherited ACEs.
SID lookup failures log a warning and fall back to default behavior.
- secure_test.go — 6 tests covering all 4 functions with owner-only and
permissive modes, error paths, and read-only open
# Usage
| File | Internal calls |
|---|---|
| internal/oauth/oauth.go │|os.MkdirAll → SecureMkdirAll (0700),
os.Chmod → SecureChmod (0600) |
| internal/config/config.go | 2x os.MkdirAll → SecureMkdirAll (0700) |
| internal/deletion/manifest.go | os.WriteFile → SecureWriteFile (0600)
|
| internal/sync/sync.go | os.WriteFile → SecureWriteFile (0600) |
| cmd/msgvault/cmd/export_eml.go | os.WriteFile → SecureWriteFile (0600)
|
| cmd/msgvault/cmd/export_attachment.go | os.OpenFile → SecureOpenFile
(0600) |
| internal/export/attachments.go | 2x os.OpenFile → SecureOpenFile (perm
param) |
| internal/update/update.go | os.WriteFile → SecureWriteFile (0600) |
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Wes McKinney <wesmckinn+git@gmail.com>1 parent 2305d72 commit 3c14ede
File tree
13 files changed
+440
-22
lines changed- cmd/msgvault/cmd
- internal
- config
- deletion
- export
- fileutil
- oauth
- sync
- update
13 files changed
+440
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
136 | | - | |
| 137 | + | |
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | | - | |
| 90 | + | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
| |||
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
39 | | - | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
64 | | - | |
65 | 66 | | |
66 | | - | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
142 | 144 | | |
143 | 145 | | |
144 | 146 | | |
145 | | - | |
| 147 | + | |
146 | 148 | | |
147 | 149 | | |
148 | 150 | | |
| |||
174 | 176 | | |
175 | 177 | | |
176 | 178 | | |
| 179 | + | |
177 | 180 | | |
178 | 181 | | |
179 | 182 | | |
180 | 183 | | |
181 | 184 | | |
182 | 185 | | |
183 | 186 | | |
| 187 | + | |
184 | 188 | | |
185 | 189 | | |
186 | 190 | | |
187 | 191 | | |
188 | 192 | | |
189 | | - | |
| 193 | + | |
190 | 194 | | |
191 | 195 | | |
192 | 196 | | |
193 | 197 | | |
194 | 198 | | |
195 | 199 | | |
| 200 | + | |
196 | 201 | | |
197 | 202 | | |
198 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
199 | 213 | | |
200 | 214 | | |
201 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
347 | 364 | | |
348 | 365 | | |
349 | 366 | | |
| |||
355 | 372 | | |
356 | 373 | | |
357 | 374 | | |
| 375 | + | |
358 | 376 | | |
359 | 377 | | |
360 | 378 | | |
| |||
368 | 386 | | |
369 | 387 | | |
370 | 388 | | |
| 389 | + | |
371 | 390 | | |
372 | 391 | | |
373 | 392 | | |
| |||
433 | 452 | | |
434 | 453 | | |
435 | 454 | | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
| 455 | + | |
| 456 | + | |
443 | 457 | | |
444 | 458 | | |
445 | 459 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
151 | 153 | | |
152 | 154 | | |
153 | 155 | | |
154 | | - | |
| 156 | + | |
155 | 157 | | |
156 | 158 | | |
157 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
322 | 324 | | |
323 | 325 | | |
324 | 326 | | |
325 | | - | |
| 327 | + | |
326 | 328 | | |
327 | 329 | | |
328 | 330 | | |
| |||
333 | 335 | | |
334 | 336 | | |
335 | 337 | | |
336 | | - | |
| 338 | + | |
337 | 339 | | |
338 | 340 | | |
339 | 341 | | |
| |||
0 commit comments