snyk 1.782.0 → 1.783.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -172481,6 +172481,8 @@ function getColorBySeverity(severity) {
172481
172481
  return chalk.yellowBright;
172482
172482
  case 'high':
172483
172483
  return chalk.redBright;
172484
+ case 'critical':
172485
+ return chalk.magentaBright;
172484
172486
  default:
172485
172487
  return chalk.whiteBright;
172486
172488
  }
@@ -172673,185 +172675,6 @@ exports.display = display;
172673
172675
 
172674
172676
  /***/ }),
172675
172677
 
172676
- /***/ 82635:
172677
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
172678
-
172679
- "use strict";
172680
-
172681
- Object.defineProperty(exports, "__esModule", ({ value: true }));
172682
- exports.getDubHashSignature = void 0;
172683
- // This module implements the "double hash" signature specification described in docs/signature_specification.md
172684
- const crypto = __webpack_require__(76417);
172685
- const binary_1 = __webpack_require__(75766);
172686
- const hashAlgorithm = 'md5';
172687
- const regex = /=/g;
172688
- var LineEndingFormat;
172689
- (function (LineEndingFormat) {
172690
- LineEndingFormat[LineEndingFormat["LINUX"] = 0] = "LINUX";
172691
- LineEndingFormat[LineEndingFormat["WINDOWS"] = 1] = "WINDOWS";
172692
- LineEndingFormat[LineEndingFormat["UNKNOWN"] = 2] = "UNKNOWN";
172693
- })(LineEndingFormat || (LineEndingFormat = {}));
172694
- const CR = 0x0d;
172695
- const LF = 0x0a;
172696
- function getDubHashSignature(filePath, fileContents, getAltHash = false) {
172697
- // Unless getAltHash is true, we only need a single hash, AKA the "half double hash".
172698
- if (!getAltHash) {
172699
- return {
172700
- path: filePath,
172701
- hashes_ffm: [
172702
- {
172703
- data: getSingleDigest(fileContents),
172704
- format: 1,
172705
- },
172706
- ],
172707
- };
172708
- }
172709
- const [digest1, digest2] = getDubHashDigests(fileContents, binary_1.isBinary(fileContents));
172710
- if (!digest1)
172711
- throw Error(`Failed to generate hash of ${filePath}`);
172712
- if (digest1 && !digest2) {
172713
- return {
172714
- path: filePath,
172715
- hashes_ffm: [
172716
- {
172717
- data: digest1,
172718
- format: 1,
172719
- },
172720
- ],
172721
- };
172722
- }
172723
- return {
172724
- path: filePath,
172725
- hashes_ffm: [
172726
- {
172727
- data: digest1,
172728
- format: 1,
172729
- },
172730
- {
172731
- data: digest2,
172732
- format: 1,
172733
- },
172734
- ],
172735
- };
172736
- }
172737
- exports.getDubHashSignature = getDubHashSignature;
172738
- function getDubHashDigests(fileContents, isBinary) {
172739
- // If the file is binary, you only produce one hash
172740
- // If the file does not have line endings, you treat it like a binary file
172741
- // If the LF character is not found, the line endings are UNKNOWN, and we produce only one hash.
172742
- const lineEndingFormat = detectLineEndingFormat(fileContents);
172743
- if (isBinary ||
172744
- !hasLineEndings(fileContents) ||
172745
- lineEndingFormat === LineEndingFormat.UNKNOWN) {
172746
- return [getSingleDigest(fileContents), null];
172747
- }
172748
- // NB: You MUST calculate the digest for the original file and store it, since transformLineEndings
172749
- // will modify fileContents buffer.
172750
- const digestForOriginal = getSingleDigest(fileContents);
172751
- const transformedFile = transformLineEndings(fileContents, lineEndingFormat);
172752
- return [digestForOriginal, getSingleDigest(transformedFile)];
172753
- }
172754
- function hasLineEndings(fileContents) {
172755
- const lineEndingBytes = new Uint8Array([LF, CR]);
172756
- for (let readIndex = 0; readIndex < fileContents.length; readIndex++) {
172757
- if (lineEndingBytes.includes(fileContents[readIndex])) {
172758
- return true;
172759
- }
172760
- }
172761
- return false;
172762
- }
172763
- function detectLineEndingFormat(fileContents) {
172764
- for (let readIndex = 0; readIndex < fileContents.length; readIndex++) {
172765
- if (fileContents[readIndex] !== LF) {
172766
- continue;
172767
- }
172768
- // If the first character in the file is LF (0x0a), the file is of type LINUX.
172769
- if (readIndex === 0) {
172770
- return LineEndingFormat.LINUX;
172771
- }
172772
- // If the file has a LF character (0x0a), check if the previous character is 0x0d (CR),
172773
- // then the newline type is WINDOWS
172774
- if (fileContents[readIndex - 1] === CR) {
172775
- return LineEndingFormat.WINDOWS;
172776
- }
172777
- return LineEndingFormat.LINUX;
172778
- }
172779
- // If the LF character is not found, the line endings are UNKNOWN.
172780
- return LineEndingFormat.UNKNOWN;
172781
- }
172782
- function transformLinuxToWindows(fileContents) {
172783
- // In worst case, file is all 0x0a bytes, so we need to allocate double the memory
172784
- const transformedFile = Buffer.alloc(2 * fileContents.length);
172785
- let writeIndex = 0;
172786
- for (let readIndex = 0; readIndex < fileContents.length; readIndex++) {
172787
- // if byte is CR (0x0d), do not write byte
172788
- if (fileContents[readIndex] === CR) {
172789
- continue;
172790
- }
172791
- // if byte is LF and targetLineEndingFormat is WINDOWS, write CR (0x0d) LF (0x0a)
172792
- // NB1: Check for targetLineEndingFormat === LineEndingFormat.WINDOWS is obviously not necessary here,
172793
- // NB2: LineEndingFormat.UNKOWN is also not possible here, due to early return in getDubHashDigests
172794
- if (fileContents[readIndex] === LF) {
172795
- transformedFile[writeIndex] = CR;
172796
- transformedFile[writeIndex + 1] = LF;
172797
- writeIndex += 2;
172798
- continue;
172799
- }
172800
- // else: write byte
172801
- transformedFile[writeIndex] = fileContents[readIndex];
172802
- writeIndex++;
172803
- }
172804
- return transformedFile.slice(0, writeIndex);
172805
- }
172806
- function transformWindowsToLinux(fileContents) {
172807
- let writeIndex = 0;
172808
- for (let readIndex = 0; readIndex < fileContents.length; readIndex++) {
172809
- // if byte is CR (0x0d), do not write byte
172810
- if (fileContents[readIndex] === CR) {
172811
- continue;
172812
- }
172813
- // if byte is LF (0x0a): if target line ending is UNIX, write LF (0x0a)
172814
- // NB1: Check for targetLineEndingFormat === LineEndingFormat.WINDOWS is obviously not necessary here,
172815
- // NB2: LineEndingFormat.UNKOWN is also not possible here, due to early return in getDubHashDigests
172816
- if (fileContents[readIndex] === LF) {
172817
- if (readIndex !== writeIndex)
172818
- fileContents[writeIndex] = LF;
172819
- writeIndex++;
172820
- continue;
172821
- }
172822
- // else: write byte
172823
- if (readIndex !== writeIndex)
172824
- fileContents[writeIndex] = fileContents[readIndex];
172825
- writeIndex++;
172826
- }
172827
- return fileContents.slice(0, writeIndex);
172828
- }
172829
- function transformLineEndings(fileContents, lineEndingFormat) {
172830
- const targetLineEndingFormat = lineEndingFormat === LineEndingFormat.LINUX
172831
- ? LineEndingFormat.WINDOWS
172832
- : LineEndingFormat.LINUX;
172833
- if (targetLineEndingFormat === LineEndingFormat.WINDOWS)
172834
- return transformLinuxToWindows(fileContents);
172835
- if (targetLineEndingFormat === LineEndingFormat.LINUX)
172836
- return transformWindowsToLinux(fileContents);
172837
- // This line is unreachable, but Typescript doesn't know it because of LineEndingFormat.UNKNOWN.
172838
- return Buffer.from('');
172839
- }
172840
- function getSingleDigest(fileContents) {
172841
- if (hashAlgorithm == 'md5') {
172842
- const hash = crypto.createHash(hashAlgorithm).update(fileContents);
172843
- return hash.digest('base64').replace(regex, '');
172844
- }
172845
- else {
172846
- // Placeholder for other planned hash algorithms, e.g. xxhash
172847
- // return xxhash.hash64(fileContents, 0xcafebabe).digest();
172848
- return '';
172849
- }
172850
- }
172851
- //# sourceMappingURL=dubhash.js.map
172852
-
172853
- /***/ }),
172854
-
172855
172678
  /***/ 75933:
172856
172679
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
172857
172680
 
@@ -172936,6 +172759,62 @@ exports.getTarget = getTarget;
172936
172759
 
172937
172760
  /***/ }),
172938
172761
 
172762
+ /***/ 42099:
172763
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
172764
+
172765
+ "use strict";
172766
+
172767
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
172768
+ exports.computeUHash = exports.computeSingleHash = exports.getHashSignature = void 0;
172769
+ const crypto = __webpack_require__(76417);
172770
+ const binary_1 = __webpack_require__(75766);
172771
+ const format_1 = __webpack_require__(72600);
172772
+ var DigestFormat;
172773
+ (function (DigestFormat) {
172774
+ DigestFormat["BASE64"] = "base64";
172775
+ DigestFormat["HEX"] = "hex";
172776
+ })(DigestFormat || (DigestFormat = {}));
172777
+ var HashAlgorithm;
172778
+ (function (HashAlgorithm) {
172779
+ HashAlgorithm["MD5"] = "md5";
172780
+ HashAlgorithm["OTHER"] = "other";
172781
+ })(HashAlgorithm || (HashAlgorithm = {}));
172782
+ const usedHashAlgorithm = HashAlgorithm.MD5;
172783
+ async function getHashSignature(path, content) {
172784
+ const hashes = await Promise.all([
172785
+ computeSingleHash(content),
172786
+ computeUHash(content),
172787
+ ]);
172788
+ return {
172789
+ path: path,
172790
+ size: content.length,
172791
+ hashes_ffm: hashes,
172792
+ };
172793
+ }
172794
+ exports.getHashSignature = getHashSignature;
172795
+ async function computeSingleHash(content) {
172796
+ const hash = crypto.createHash(usedHashAlgorithm).update(content);
172797
+ const base64Digest = hash.digest(DigestFormat.BASE64).replace(/=/g, '');
172798
+ return {
172799
+ data: base64Digest,
172800
+ format: 1,
172801
+ };
172802
+ }
172803
+ exports.computeSingleHash = computeSingleHash;
172804
+ async function computeUHash(content) {
172805
+ const file = binary_1.isBinary(content) ? content : format_1.removeWhitespaces(content);
172806
+ const hash = crypto.createHash(usedHashAlgorithm).update(file);
172807
+ const hexDigest = hash.digest(DigestFormat.HEX).slice(0, 24);
172808
+ return {
172809
+ data: hexDigest,
172810
+ format: 3,
172811
+ };
172812
+ }
172813
+ exports.computeUHash = computeUHash;
172814
+ //# sourceMappingURL=hash.js.map
172815
+
172816
+ /***/ }),
172817
+
172939
172818
  /***/ 96957:
172940
172819
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
172941
172820
 
@@ -172978,7 +172857,7 @@ async function scan(options) {
172978
172857
  const start = Date.now();
172979
172858
  const filePaths = await find_1.find(options.path);
172980
172859
  debug_1.debug('%d files found \n', filePaths.length);
172981
- const allSignatures = await signatures_1.getSignaturesByAlgorithm(filePaths);
172860
+ const allSignatures = await signatures_1.getSignatures(filePaths);
172982
172861
  const filteredSignatures = allSignatures.filter((s) => {
172983
172862
  return s !== null;
172984
172863
  });
@@ -173038,115 +172917,115 @@ exports.scan = scan;
173038
172917
  "use strict";
173039
172918
 
173040
172919
  Object.defineProperty(exports, "__esModule", ({ value: true }));
173041
- exports.getSignaturesByAlgorithm = void 0;
172920
+ exports.getSignatures = void 0;
173042
172921
  const fs_1 = __webpack_require__(35747);
173043
- const dubhash_1 = __webpack_require__(82635);
173044
- const uhash_1 = __webpack_require__(40);
172922
+ const hash_1 = __webpack_require__(42099);
173045
172923
  const pMap = __webpack_require__(81334);
173046
172924
  const { readFile } = fs_1.promises;
173047
- async function getSignaturesByAlgorithm(filePaths, hashType = 'dubhash') {
173048
- if (hashType !== 'dubhash' && hashType !== 'uhash') {
173049
- throw new Error(`Unsupported hashType ${hashType}`);
173050
- }
173051
- let signatureMapperToBeUsed = getDubHashSignatureMapper;
173052
- if (hashType === 'uhash') {
173053
- signatureMapperToBeUsed = getUHashSignatureMapper;
173054
- }
173055
- return await pMap(filePaths, signatureMapperToBeUsed, { concurrency: 20 });
173056
- }
173057
- exports.getSignaturesByAlgorithm = getSignaturesByAlgorithm;
173058
- async function getDubHashSignatureMapper(filePath) {
173059
- const fileContents = await readFile(filePath);
173060
- if (fileContents.length === 0)
173061
- return null;
173062
- return dubhash_1.getDubHashSignature(filePath, fileContents);
173063
- }
173064
- async function getUHashSignatureMapper(filePath) {
173065
- const fileContents = await readFile(filePath);
173066
- if (fileContents.length === 0)
173067
- return null;
173068
- return uhash_1.getUhashSignature(filePath, fileContents);
172925
+ async function getSignatures(paths) {
172926
+ return pMap(paths, async (path) => {
172927
+ const content = await readFile(path);
172928
+ return content.length > 0 ? await hash_1.getHashSignature(path, content) : null;
172929
+ }, { concurrency: 20 });
173069
172930
  }
172931
+ exports.getSignatures = getSignatures;
173070
172932
  //# sourceMappingURL=signatures.js.map
173071
172933
 
173072
172934
  /***/ }),
173073
172935
 
173074
- /***/ 40:
173075
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
172936
+ /***/ 75766:
172937
+ /***/ ((__unused_webpack_module, exports) => {
173076
172938
 
173077
172939
  "use strict";
173078
172940
 
173079
172941
  Object.defineProperty(exports, "__esModule", ({ value: true }));
173080
- exports.getUhashSignature = void 0;
173081
- // This module implements the "uhash" signature specification described in docs/signature_specification.md
173082
- const crypto = __webpack_require__(76417);
173083
- const binary_1 = __webpack_require__(75766);
173084
- const hashAlgorithm = 'md5';
173085
- const Utf8Bom = Buffer.from(new Uint8Array([0xef, 0xbb, 0xbf]));
173086
- function getUhashSignature(filePath, fileContents) {
173087
- const digest = getUhashDigest(fileContents, binary_1.isBinary(fileContents));
173088
- const data = digest.slice(0, 24);
173089
- return {
173090
- path: filePath,
173091
- hashes_ffm: [
173092
- {
173093
- data,
173094
- format: 3,
173095
- },
173096
- ],
173097
- };
173098
- }
173099
- exports.getUhashSignature = getUhashSignature;
173100
- function getUhashDigest(fileContents, isBinary) {
173101
- if (hashAlgorithm !== 'md5') {
173102
- // placeholder for non-md5 hashing algorithm, e.g. xxhash
173103
- throw new Error(`hashAlgorithm ${hashAlgorithm} is not supported`);
173104
- }
173105
- const file = isBinary ? fileContents : removeUnwantedBytes(fileContents);
173106
- const hash = crypto.createHash(hashAlgorithm).update(file);
173107
- return hash.digest('hex');
173108
- }
173109
- function removeUnwantedBytes(fileBuffer) {
173110
- const startingIndex = isUtf8BomPresent(fileBuffer) ? 3 : 0;
173111
- return removeWhitespaceBytewise(fileBuffer, startingIndex);
173112
- }
173113
- function isUtf8BomPresent(fileBuffer) {
173114
- if (fileBuffer.length < 3)
173115
- return false;
173116
- return Utf8Bom.compare(fileBuffer.subarray(0, 3)) === 0;
173117
- }
173118
- function includeChar(c) {
173119
- return (c > 0x20 ||
173120
- (c != 0x20 && c != 0x0d && c != 0x0a && c != 0x09 && c != 0x0b && c != 0x0c));
173121
- }
173122
- function removeWhitespaceBytewise(fileBuffer, startingIndex) {
173123
- let writeIndex = 0;
173124
- for (let readIndex = startingIndex; readIndex < fileBuffer.length; readIndex++) {
173125
- const c = fileBuffer[readIndex];
173126
- if (includeChar(c)) {
173127
- fileBuffer[writeIndex] = c;
173128
- writeIndex++;
173129
- }
173130
- }
173131
- return fileBuffer.slice(0, writeIndex);
172942
+ exports.isBinary = void 0;
172943
+ function isBinary(content) {
172944
+ return content.includes(0);
173132
172945
  }
173133
- //# sourceMappingURL=uhash.js.map
172946
+ exports.isBinary = isBinary;
172947
+ //# sourceMappingURL=binary.js.map
173134
172948
 
173135
172949
  /***/ }),
173136
172950
 
173137
- /***/ 75766:
172951
+ /***/ 72600:
173138
172952
  /***/ ((__unused_webpack_module, exports) => {
173139
172953
 
173140
172954
  "use strict";
173141
172955
 
173142
172956
  Object.defineProperty(exports, "__esModule", ({ value: true }));
173143
- exports.isBinary = void 0;
173144
- function isBinary(fileBuffer) {
173145
- // The spec defines a binary file as anything containing a null byte
173146
- return fileBuffer.includes(0);
172957
+ exports.removeWhitespaces = exports.removeWhitespaceBytewise = exports.isNotWhiteSpace = exports.isUtf8BomPresent = void 0;
172958
+ const Utf8Bom = Buffer.from(new Uint8Array([0xef, 0xbb, 0xbf]));
172959
+ const asciiChars = {
172960
+ space: 0x20,
172961
+ carriageReturn: 0x0d,
172962
+ newLine: 0x0a,
172963
+ horizontalTab: 0x09,
172964
+ verticalTab: 0x0b,
172965
+ newPage: 0x0c,
172966
+ };
172967
+ /**
172968
+ * Check if the UTF-8 BOM is present in the first three bytes
172969
+ *
172970
+ * @param {FileContent} content
172971
+ * @returns {boolean}
172972
+ */
172973
+ function isUtf8BomPresent(content) {
172974
+ if (content.length < 3) {
172975
+ return false;
172976
+ }
172977
+ return Utf8Bom.compare(content.subarray(0, 3)) === 0;
173147
172978
  }
173148
- exports.isBinary = isBinary;
173149
- //# sourceMappingURL=binary.js.map
172979
+ exports.isUtf8BomPresent = isUtf8BomPresent;
172980
+ /**
172981
+ * Check if char is not whitespace
172982
+ *
172983
+ * @param {number} char
172984
+ * @returns {boolean}
172985
+ */
172986
+ function isNotWhiteSpace(char) {
172987
+ return (char > asciiChars.space ||
172988
+ (char != asciiChars.space &&
172989
+ char != asciiChars.carriageReturn &&
172990
+ char != asciiChars.newLine &&
172991
+ char != asciiChars.horizontalTab &&
172992
+ char != asciiChars.verticalTab &&
172993
+ char != asciiChars.newPage));
172994
+ }
172995
+ exports.isNotWhiteSpace = isNotWhiteSpace;
172996
+ /**
172997
+ * Remove whitespaces from the file
172998
+ *
172999
+ * @param {FileContent} content
173000
+ * @param {number} startingIndex
173001
+ * @returns {FileContent}
173002
+ */
173003
+ function removeWhitespaceBytewise(content, startingIndex) {
173004
+ let writeIndex = 0;
173005
+ for (let readIndex = startingIndex; readIndex < content.length; readIndex++) {
173006
+ const c = content[readIndex];
173007
+ if (isNotWhiteSpace(c)) {
173008
+ content[writeIndex] = c;
173009
+ writeIndex++;
173010
+ }
173011
+ }
173012
+ return content.slice(0, writeIndex);
173013
+ }
173014
+ exports.removeWhitespaceBytewise = removeWhitespaceBytewise;
173015
+ /**
173016
+ * Remove unwanted bytes from the file
173017
+ *
173018
+ * If it is UTF-8 BOM we start parsing the file content from index 3
173019
+ *
173020
+ * @param {FileContent} content
173021
+ * @returns {FileContent}
173022
+ */
173023
+ function removeWhitespaces(content) {
173024
+ const startingIndex = isUtf8BomPresent(content) ? 3 : 0;
173025
+ return removeWhitespaceBytewise(content, startingIndex);
173026
+ }
173027
+ exports.removeWhitespaces = removeWhitespaces;
173028
+ //# sourceMappingURL=format.js.map
173150
173029
 
173151
173030
  /***/ }),
173152
173031