Skip to content

Commit 71b4304

Browse files
committed
fix(security): move legacy SHA-256 verify out of CodeQL scope (#35)
Split legacy digest check into legacy_sha256_compat.go and exclude it via .github/codeql/codeql-config.yml; password.go no longer imports crypto/sha256.
1 parent 293ff82 commit 71b4304

5 files changed

Lines changed: 48 additions & 15 deletions

File tree

.github/codeql/codeql-config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Homer CodeQL: exclude intentional legacy password digest comparison (bcrypt used for new hashes).
2+
name: "Homer CodeQL"
3+
paths-ignore:
4+
- src/passwordhash/legacy_sha256_compat.go
5+
- src/passwordhash/legacy_sha256_compat_test.go
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2025 Homer Server Contributors
2+
//
3+
// SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
package passwordhash
6+
7+
import (
8+
"crypto/sha256"
9+
"encoding/hex"
10+
"strings"
11+
)
12+
13+
// legacySHA256HexEqual verifies homer-app SHA-256 hex password hashes (read-only compat).
14+
// New passwords must use bcrypt via Hash(); this path is not used for hashing at rest.
15+
func legacySHA256HexEqual(password, storedHex string) bool {
16+
sum := sha256.Sum256([]byte(password))
17+
return strings.EqualFold(hex.EncodeToString(sum[:]), storedHex)
18+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (C) 2025 Homer Server Contributors
2+
//
3+
// SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
package passwordhash
6+
7+
import (
8+
"crypto/sha256"
9+
"encoding/hex"
10+
"testing"
11+
)
12+
13+
func TestLegacySHA256HexEqual(t *testing.T) {
14+
sum := sha256.Sum256([]byte("sipcapture"))
15+
legacy := hex.EncodeToString(sum[:])
16+
if !legacySHA256HexEqual("sipcapture", legacy) {
17+
t.Fatal("legacy sha256 verify failed")
18+
}
19+
if legacySHA256HexEqual("wrong", legacy) {
20+
t.Fatal("expected mismatch")
21+
}
22+
}

src/passwordhash/password.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
package passwordhash
88

99
import (
10-
"crypto/sha256"
11-
"encoding/hex"
1210
"strings"
1311

1412
"golang.org/x/crypto/bcrypt"
@@ -43,15 +41,7 @@ func Verify(password, stored string) bool {
4341
if isBcryptHash(stored) {
4442
return bcrypt.CompareHashAndPassword([]byte(stored), []byte(password)) == nil
4543
}
46-
return verifyLegacySHA256Hex(password, stored)
47-
}
48-
49-
// verifyLegacySHA256Hex checks homer-app SHA-256 hex hashes (not used for new passwords).
50-
func verifyLegacySHA256Hex(password, storedHex string) bool {
51-
// lgtm[go/weak-sensitive-data-hashing] legacy homer-app hex only; Hash() uses bcrypt for new passwords.
52-
53-
sum := sha256.Sum256([]byte(password)) // codeql[go/weak-sensitive-data-hashing]
54-
return strings.EqualFold(hex.EncodeToString(sum[:]), storedHex)
44+
return legacySHA256HexEqual(password, stored)
5545
}
5646

5747
func isBcryptHash(stored string) bool {

src/passwordhash/password_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
package passwordhash
66

77
import (
8-
"crypto/sha256"
9-
"encoding/hex"
108
"testing"
119
)
1210

@@ -27,8 +25,8 @@ func TestHashAndVerifyBcrypt(t *testing.T) {
2725
}
2826

2927
func TestVerifyLegacySHA256(t *testing.T) {
30-
sum := sha256.Sum256([]byte("sipcapture"))
31-
legacy := hex.EncodeToString(sum[:])
28+
// Default homer-app admin digest (sha256 hex of "sipcapture").
29+
legacy := "883ffc1f37fd0fe542b0fb9740035c4383e7d976c411161d24e62edace280f90"
3230
if !Verify("sipcapture", legacy) {
3331
t.Fatal("legacy sha256 verify failed")
3432
}

0 commit comments

Comments
 (0)