Commit 2511c02
authored
fix: replace deprecated scmp with crypto.timingSafeEqual (#15322)
# Overview
Removes the deprecated `scmp` package and replaces it with Node.js's
native `crypto.timingSafeEqual()` for timing-safe password hash
comparison.
Resolves ECMS-356
## Key Changes
- **Replace scmp with crypto.timingSafeEqual**
- Added length pre-check before comparison (required since
`timingSafeEqual` throws on length mismatch, whereas `scmp` returned
false)
- **Remove scmp dependency**
- Eliminates deprecation warning: "scmp@2.1.0: Just use Node.js's
crypto.timingSafeEqual()"
## Design Decisions
The length pre-check (`hashBuffer.length === storedHashBuffer.length`)
preserves the original `scmp` behavior of returning false for mismatched
lengths, rather than throwing an error. This maintains backward
compatibility and security semantics.
## Overall Flow
```mermaid
sequenceDiagram
participant Client
participant authenticateLocalStrategy
participant crypto
Client->>authenticateLocalStrategy: password + doc (hash, salt)
authenticateLocalStrategy->>crypto: pbkdf2(password, salt)
crypto-->>authenticateLocalStrategy: hashBuffer
authenticateLocalStrategy->>authenticateLocalStrategy: Check buffer lengths match
alt Lengths match
authenticateLocalStrategy->>crypto: timingSafeEqual(hashBuffer, storedHashBuffer)
crypto-->>authenticateLocalStrategy: boolean
else Lengths differ
authenticateLocalStrategy-->>Client: null (fail fast)
end
authenticateLocalStrategy-->>Client: doc | null
```1 parent 3e27155 commit 2511c02
File tree
4 files changed
+75
-18
lines changed- packages/payload
- src/auth/strategies/local
4 files changed
+75
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
129 | 128 | | |
130 | 129 | | |
131 | 130 | | |
| |||
Lines changed: 63 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | 3 | | |
6 | 4 | | |
7 | 5 | | |
| |||
23 | 21 | | |
24 | 22 | | |
25 | 23 | | |
26 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments