Conversation
Pull Request Test Coverage Report for Build 18886117013Details
💛 - Coveralls |
2ce3152 to
89f4a67
Compare
ec771cb to
7d444d1
Compare
0210cb1 to
e3ccb10
Compare
e3ccb10 to
e2901e9
Compare
e3d4525 to
ffeaf8b
Compare
e11e24f to
d6ded5e
Compare
d4ff2de to
87717a3
Compare
2e38c3f to
a40e62f
Compare
8acfc86 to
9400017
Compare
aa0fea6 to
934fd1c
Compare
| sha1sum.update(data); | ||
| const s = sha1sum.digest("hex"); | ||
| const sha1sum = createHash('sha1') | ||
| sha1sum.update(data) |
Check failure
Code scanning / CodeQL
Use of a broken or weak cryptographic algorithm High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 days ago
General approach: Replace the use of SHA‑1 with a modern, secure hash such as SHA‑256 (or SHA‑512) in the generate function in src/util/mac.ts. Since the function only uses the hex digest as a source of characters to fill a MAC template, changing the hash algorithm will not alter the external format, just the deterministic mapping from input data to MAC‑like address.
Best concrete fix without changing functionality:
In src/util/mac.ts, change createHash('sha1') to createHash('sha256'). No other code changes are required because:
createHash('sha256')is supported by Node’s built‑incryptomodule already imported ascreateHash.- The hex digest from SHA‑256 is longer than SHA‑1, but
generateonly uses as many characters as needed to fill'xx:xx:xx:xx:xx:xx'(12 hex characters), so behavior remains consistent: a deterministic, uppercase MAC‑formatted string derived from the input.
File/line details:
- File:
src/util/mac.ts- Around line 17: update
const sha1sum = createHash('sha1')to use SHA‑256 instead. - Variable names can remain the same or be updated; to minimize change, we can keep the variable name even though it now holds a SHA‑256 hash object. This has no functional impact.
- Around line 17: update
No new methods or imports are required; we continue to use Node’s crypto module.
| @@ -14,9 +14,9 @@ | ||
| } | ||
|
|
||
| export function generate(data: string | Buffer | NodeJS.TypedArray | DataView): MacAddress { | ||
| const sha1sum = createHash('sha1') | ||
| sha1sum.update(data) | ||
| const s = sha1sum.digest('hex') | ||
| const hash = createHash('sha256') | ||
| hash.update(data) | ||
| const s = hash.digest('hex') | ||
|
|
||
| let i = 0 | ||
| return 'xx:xx:xx:xx:xx:xx'.replace(PLACEHOLDER_RE, () => s[i++]).toUpperCase() |
Related PRs:
hap-nodejs: v2.0.0-beta HAP-NodeJS#1094homebridge: v2.0.0-beta #3816@homebridge/hap-client: v3.0.0-beta hap-client#21homebridge-config-ui-x: v5.0.0-beta homebridge-config-ui-x#2449For Users:
For Plugin Developers:
Please visit the following link to learn more about the changes and how to prepare:
Added
-Dsetting per child bridgeChanged
commonjstoesmmodules@antfu/eslint-configjesttovitestfor testingv18Removed
--remove-orphansflagHomebridge Dependencies
hap-nodejs@v2.0.0-beta