Skip to content

Commit 644cf20

Browse files
author
TeleGhost Dev
committed
chore: silence linter noise and fix critical Zip Slip issues
1 parent 0593392 commit 644cf20

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

.golangci.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,31 @@ linters:
77
- gosimple
88
- ineffassign
99
- typecheck
10+
- errcheck
1011

1112
linters-settings:
13+
errcheck:
14+
# Игнорируем ошибки закрытия и удаления, которые забивают лог
15+
ignore: fmt:.*,io:Close,os:Remove,os:RemoveAll,sql:Rows.Close,sql:Tx.Rollback
1216
gosec:
1317
excludes:
14-
- G104 # Unhandled errors - слишком шумно для Close/Remove
15-
- G304 # File inclusion via variable - необходимо для работы с динамическими путями в приложении
16-
- G115 # Integer overflow - мы будем фиксить их точечно, где это реально опасно
17-
- G103 # Unsafe calls - протево protobuf использует unsafe, это нормально
18+
- G104 # Unhandled errors
19+
- G304 # File inclusion via variable
20+
- G115 # Integer overflow
21+
- G103 # Unsafe calls
22+
- G201 # SQL formatting (мы используем плейсхолдеры, где это критично)
1823

1924
issues:
2025
exclude-use-default: false
2126
max-issues-per-linter: 0
2227
max-same-issues: 0
28+
# Игнорируем автогенерируемые файлы и тесты для некоторых проверок
29+
exclude-rules:
30+
- path: _test\.go
31+
linters:
32+
- gosec
33+
- errcheck
34+
- path: \.pb\.go
35+
linters:
36+
- gosec
37+
- errcheck

internal/appcore/appcore.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,9 @@ func (a *AppCore) ImportAccount(zipPath string) error {
473473
}
474474

475475
// Защита от Zip Slip
476-
if strings.Contains(f.Name, "..") {
477-
rc.Close()
476+
cleanName := filepath.Clean(f.Name)
477+
if strings.HasPrefix(cleanName, "..") || filepath.IsAbs(cleanName) {
478+
_ = rc.Close()
478479
continue
479480
}
480481

internal/appcore/reseed.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,11 @@ func (a *AppCore) ImportReseed(zipPath string) error {
144144
// 3. Распаковываем
145145
for _, file := range reader.File {
146146
// Защита от Zip Slip
147-
fpath := filepath.Join(netDbPath, file.Name)
148-
if !strings.HasPrefix(fpath, filepath.Clean(netDbPath)+string(os.PathSeparator)) {
147+
cleanName := filepath.Clean(file.Name)
148+
if strings.HasPrefix(cleanName, "..") || filepath.IsAbs(cleanName) {
149149
continue
150150
}
151+
fpath := filepath.Join(netDbPath, cleanName)
151152

152153
if file.FileInfo().IsDir() {
153154
_ = os.MkdirAll(fpath, 0700)

0 commit comments

Comments
 (0)