Skip to content

Commit

Permalink
Add MD4 shim for Webpack4 on Node18+ (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderBelokon authored Jan 7, 2025
1 parent beef9b4 commit 3f98954
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions batfish.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

require('./src/md4-shim');

const path = require('path');
// eslint-disable-next-line
const navigationStructure = require('./_tmp_assembly/navigation.json');
Expand Down
22 changes: 22 additions & 0 deletions src/md4-shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const crypto = require('crypto')
// MD4 algorithm is not available anymore in NodeJS 17+ (because of lib SSL 3).
// https://stackoverflow.com/a/72219174/1447466
// config.output.hashFunction = 'md5'
// is supposed to disables MD4, but it doesn't work correctly until
// https://github.com/webpack/webpack/pull/14306
try {
crypto.createHash('md4')
} catch (e) {
let printed = false
const print = alg => {
if (alg != 'md4') return
if (printed) return
printed = true
console.warn('MD4 is unsupported, replacing it with MD5')
}
const createHash = crypto.createHash
crypto.createHash = (alg, ...params) => {
print(alg)
return createHash(alg == 'md4' ? 'md5' : alg, ...params)
}
}

0 comments on commit 3f98954

Please sign in to comment.