diff --git a/CHANGELOG.md b/CHANGELOG.md index e4e3be87..b609c201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -725,7 +725,7 @@ Breaking changes: [10.11.0]: https://github.com/gchq/CyberChef/releases/tag/v10.11.0 [10.10.0]: https://github.com/gchq/CyberChef/releases/tag/v10.10.0 [10.9.0]: https://github.com/gchq/CyberChef/releases/tag/v10.9.0 -[10.8.0]: https://github.com/gchq/CyberChef/releases/tag/v10.7.0 +[10.8.0]: https://github.com/gchq/CyberChef/releases/tag/v10.8.0 [10.7.0]: https://github.com/gchq/CyberChef/releases/tag/v10.7.0 [10.6.0]: https://github.com/gchq/CyberChef/releases/tag/v10.6.0 [10.5.0]: https://github.com/gchq/CyberChef/releases/tag/v10.5.0 diff --git a/src/core/Chef.mjs b/src/core/Chef.mjs index 5be10868..426d9643 100755 --- a/src/core/Chef.mjs +++ b/src/core/Chef.mjs @@ -138,6 +138,8 @@ class Chef { if (!highlights) return false; + if (direction === "reverse") highlights.reverse(); + for (let i = 0; i < highlights.length; i++) { // Remove multiple highlights before processing again pos = [pos[0]]; diff --git a/src/core/dishTypes/DishType.mjs b/src/core/dishTypes/DishType.mjs index d89e3c0b..04da53dc 100644 --- a/src/core/dishTypes/DishType.mjs +++ b/src/core/dishTypes/DishType.mjs @@ -11,7 +11,7 @@ class DishType { /** - * Warn translations dont work without value from bind + * Warn translations don't work without value from bind */ static checkForValue(value) { if (value === undefined) { diff --git a/src/core/errors/ExcludedOperationError.mjs b/src/core/errors/ExcludedOperationError.mjs index 2972c31d..657051f2 100644 --- a/src/core/errors/ExcludedOperationError.mjs +++ b/src/core/errors/ExcludedOperationError.mjs @@ -1,5 +1,5 @@ /** - * Custom error type for handling operation that isnt included in node.js API + * Custom error type for handling operation that isn't included in node.js API * * @author d98762625 [d98762625@gmail.com] * @copyright Crown Copyright 2018 diff --git a/src/core/operations/GenerateDeBruijnSequence.mjs b/src/core/operations/GenerateDeBruijnSequence.mjs index f28d421f..1ac415da 100644 --- a/src/core/operations/GenerateDeBruijnSequence.mjs +++ b/src/core/operations/GenerateDeBruijnSequence.mjs @@ -50,6 +50,14 @@ class GenerateDeBruijnSequence extends Operation { throw new OperationError("Invalid alphabet size, required to be between 2 and 9 (inclusive)."); } + if (!Number.isInteger(k)) { + throw new OperationError("Invalid alphabet size, required to be integer."); + } + + if (!Number.isInteger(n)) { + throw new OperationError("Invalid key length, required to be integer."); + } + if (n < 2) { throw new OperationError("Invalid key length, required to be at least 2."); } diff --git a/src/core/operations/ParityBit.mjs b/src/core/operations/ParityBit.mjs index c5ac1d1e..35912f3c 100644 --- a/src/core/operations/ParityBit.mjs +++ b/src/core/operations/ParityBit.mjs @@ -20,7 +20,7 @@ class ParityBit extends Operation { this.name = "Parity Bit"; this.module = "Default"; - this.description = "A parity bit, or check bit, is the simplest form of error detection. It is a bit which is added to a string of bits and represents if the number of 1's in the binary string is an even number or odd number.

If a delimiter is specified, the parity bit calculation will be performed on each 'block' of the input data, where the blocks are created by slicing the input at each occurence of the delimiter character"; + this.description = "A parity bit, or check bit, is the simplest form of error detection. It is a bit which is added to a string of bits and represents if the number of 1's in the binary string is an even number or odd number.

If a delimiter is specified, the parity bit calculation will be performed on each 'block' of the input data, where the blocks are created by slicing the input at each occurrence of the delimiter character"; this.infoURL = "https://wikipedia.org/wiki/Parity_bit"; this.inputType = "string"; this.outputType = "string"; diff --git a/src/core/operations/ParseIPv4Header.mjs b/src/core/operations/ParseIPv4Header.mjs index a1ab93b3..65a8b63f 100644 --- a/src/core/operations/ParseIPv4Header.mjs +++ b/src/core/operations/ParseIPv4Header.mjs @@ -74,7 +74,7 @@ class ParseIPv4Header extends Operation { checksum = input[10] << 8 | input[11], srcIP = input[12] << 24 | input[13] << 16 | input[14] << 8 | input[15], dstIP = input[16] << 24 | input[17] << 16 | input[18] << 8 | input[19], - checksumHeader = input.slice(0, 10).concat([0, 0]).concat(input.slice(12, 20)); + checksumHeader = [...input.slice(0, 10), 0, 0, ...input.slice(12, 20)]; let version = (input[0] >>> 4) & 0x0f, options = []; diff --git a/src/core/operations/SHA2.mjs b/src/core/operations/SHA2.mjs index ecdc4cc5..9844070d 100644 --- a/src/core/operations/SHA2.mjs +++ b/src/core/operations/SHA2.mjs @@ -20,7 +20,7 @@ class SHA2 extends Operation { this.name = "SHA2"; this.module = "Crypto"; - this.description = "The SHA-2 (Secure Hash Algorithm 2) hash functions were designed by the NSA. SHA-2 includes significant changes from its predecessor, SHA-1. The SHA-2 family consists of hash functions with digests (hash values) that are 224, 256, 384 or 512 bits: SHA224, SHA256, SHA384, SHA512.

The message digest algorithm for SHA256 variants consists, by default, of 64 rounds, and for SHA512 variants, it is, by default, 160."; + this.description = "The SHA-2 (Secure Hash Algorithm 2) hash functions were designed by the NSA. SHA-2 includes significant changes from its predecessor, SHA-1. The SHA-2 family consists of hash functions with digests (hash values) that are 224, 256, 384 or 512 bits: SHA224, SHA256, SHA384, SHA512.

The message digest algorithm for SHA256 variants consists, by default, of 64 rounds, and for SHA512 variants, it is, by default, 160."; this.infoURL = "https://wikipedia.org/wiki/SHA-2"; this.inputType = "ArrayBuffer"; this.outputType = "string"; diff --git a/src/core/operations/ToHexdump.mjs b/src/core/operations/ToHexdump.mjs index a52b0451..f73f2608 100644 --- a/src/core/operations/ToHexdump.mjs +++ b/src/core/operations/ToHexdump.mjs @@ -8,6 +8,8 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; import OperationError from "../errors/OperationError.mjs"; +const MAX_WIDTH = 65536; + /** * To Hexdump operation */ @@ -30,7 +32,8 @@ class ToHexdump extends Operation { "name": "Width", "type": "number", "value": 16, - "min": 1 + "min": 1, + "max": MAX_WIDTH }, { "name": "Upper case hex", @@ -63,6 +66,9 @@ class ToHexdump extends Operation { if (length < 1 || Math.round(length) !== length) throw new OperationError("Width must be a positive integer"); + if (length > MAX_WIDTH) + throw new OperationError(`Width must be no more than ${MAX_WIDTH}`); + const lines = []; for (let i = 0; i < data.length; i += length) { let lineNo = Utils.hex(i, 8); diff --git a/src/core/operations/XORChecksum.mjs b/src/core/operations/XORChecksum.mjs index 1603a265..ca9c6fac 100644 --- a/src/core/operations/XORChecksum.mjs +++ b/src/core/operations/XORChecksum.mjs @@ -7,12 +7,12 @@ import Operation from "../Operation.mjs"; import Utils from "../Utils.mjs"; import { toHex } from "../lib/Hex.mjs"; +import OperationError from "../errors/OperationError.mjs"; /** * XOR Checksum operation */ class XORChecksum extends Operation { - /** * XORChecksum constructor */ @@ -21,7 +21,8 @@ class XORChecksum extends Operation { this.name = "XOR Checksum"; this.module = "Crypto"; - this.description = "XOR Checksum splits the input into blocks of a configurable size and performs the XOR operation on these blocks."; + this.description = + "XOR Checksum splits the input into blocks of a configurable size and performs the XOR operation on these blocks."; this.infoURL = "https://wikipedia.org/wiki/XOR"; this.inputType = "ArrayBuffer"; this.outputType = "string"; @@ -29,7 +30,7 @@ class XORChecksum extends Operation { { name: "Blocksize", type: "number", - value: 4 + value: 4, }, ]; } @@ -41,6 +42,12 @@ class XORChecksum extends Operation { */ run(input, args) { const blocksize = args[0]; + + + if (!Number.isInteger(blocksize) || blocksize <= 0) { + throw new OperationError("Blocksize must be a positive integer."); + } + input = new Uint8Array(input); const res = Array(blocksize); diff --git a/tests/operations/tests/Hexdump.mjs b/tests/operations/tests/Hexdump.mjs index 6eb486db..12d04492 100644 --- a/tests/operations/tests/Hexdump.mjs +++ b/tests/operations/tests/Hexdump.mjs @@ -126,6 +126,17 @@ TestRegister.addTests([ } ], }, + { + name: "To Hexdump: Width too large", + input: "H", + expectedOutput: "Width must be no more than 65536", + recipeConfig: [ + { + op: "To Hexdump", + args: [155555555555555, false, false, false] + } + ], + }, { name: "From Hexdump: xxd", input: `00000000: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f ................ diff --git a/tests/operations/tests/ParseIPv4Header.mjs b/tests/operations/tests/ParseIPv4Header.mjs index 47c2592a..ddebe3b9 100644 --- a/tests/operations/tests/ParseIPv4Header.mjs +++ b/tests/operations/tests/ParseIPv4Header.mjs @@ -19,5 +19,16 @@ TestRegister.addTests([ args: ["Hex", "Data (raw)"] } ] + }, + { + name: "Parse IPv4 header: regression for Uint8Array.concat crash on truncated raw input", + input: "\x45\x00\x00\x14\x00\x00\x00\x00\x40\x06\x00\x00", + expectedOutput: "", + recipeConfig: [ + { + op: "Parse IPv4 header", + args: ["Raw", "Data (raw)"] + } + ] } ]);