mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
update more ENVIRONMENT_IS_* calls after merge, update some test paths, comments. Remove vulnerability
This commit is contained in:
parent
368f508b17
commit
e03ff22ba8
10 changed files with 31 additions and 19 deletions
6
package-lock.json
generated
6
package-lock.json
generated
|
@ -6840,9 +6840,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"js-yaml": {
|
"js-yaml": {
|
||||||
"version": "3.13.0",
|
"version": "3.13.1",
|
||||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.0.tgz",
|
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz",
|
||||||
"integrity": "sha512-pZZoSxcCYco+DIKBTimr67J6Hy+EYGZDY/HCWC+iAEA9h1ByhMXAIVUXMcMFpOCxQ/xjXmPI2MkDL5HRm5eFrQ==",
|
"integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"argparse": "^1.0.7",
|
"argparse": "^1.0.7",
|
||||||
|
|
|
@ -9,6 +9,7 @@ import OperationError from "./errors/OperationError";
|
||||||
import Operation from "./Operation";
|
import Operation from "./Operation";
|
||||||
import DishError from "./errors/DishError";
|
import DishError from "./errors/DishError";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
|
import { isWorkerEnvironment } from "./Utils";
|
||||||
|
|
||||||
// Cache container for modules
|
// Cache container for modules
|
||||||
let modules = null;
|
let modules = null;
|
||||||
|
@ -202,7 +203,7 @@ class Recipe {
|
||||||
input = await dish.get(op.inputType);
|
input = await dish.get(op.inputType);
|
||||||
log.debug(`Executing operation '${op.name}'`);
|
log.debug(`Executing operation '${op.name}'`);
|
||||||
|
|
||||||
if (ENVIRONMENT_IS_WORKER()) {
|
if (isWorkerEnvironment()) {
|
||||||
self.sendStatusMessage(`Baking... (${i+1}/${this.opList.length})`);
|
self.sendStatusMessage(`Baking... (${i+1}/${this.opList.length})`);
|
||||||
self.sendProgressMessage(i + 1, this.opList.length);
|
self.sendProgressMessage(i + 1, this.opList.length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1154,17 +1154,24 @@ class Utils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the code is running in a Node.js environment
|
* Check whether the code is running in a Node.js environment
|
||||||
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
export function isNodeEnvironment() {
|
export function isNodeEnvironment() {
|
||||||
return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/**
|
||||||
|
* Check whether the code is running in a web environment
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
export function isWebEnvironment() {
|
export function isWebEnvironment() {
|
||||||
return typeof window === "object";
|
return typeof window === "object";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/**
|
||||||
|
* Check whether the code is running in a worker
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
export function isWorkerEnvironment() {
|
export function isWorkerEnvironment() {
|
||||||
return typeof importScripts === "function";
|
return typeof importScripts === "function";
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64";
|
import { toBase64 } from "../lib/Base64";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,7 +132,7 @@ class AddTextToImage extends Operation {
|
||||||
throw new OperationError(`Error loading image. (${err})`);
|
throw new OperationError(`Error loading image. (${err})`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Adding text to image...");
|
self.sendStatusMessage("Adding text to image...");
|
||||||
|
|
||||||
const fontsMap = {};
|
const fontsMap = {};
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import Bzip2 from "libbzip2-wasm";
|
import Bzip2 from "libbzip2-wasm";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bzip2 Compress operation
|
* Bzip2 Compress operation
|
||||||
|
@ -51,10 +52,10 @@ class Bzip2Compress extends Operation {
|
||||||
if (input.byteLength <= 0) {
|
if (input.byteLength <= 0) {
|
||||||
throw new OperationError("Please provide an input.");
|
throw new OperationError("Please provide an input.");
|
||||||
}
|
}
|
||||||
if (ENVIRONMENT_IS_WORKER()) self.sendStatusMessage("Loading Bzip2...");
|
if (isWorkerEnvironment()) self.sendStatusMessage("Loading Bzip2...");
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
Bzip2().then(bzip2 => {
|
Bzip2().then(bzip2 => {
|
||||||
if (ENVIRONMENT_IS_WORKER()) self.sendStatusMessage("Compressing data...");
|
if (isWorkerEnvironment()) self.sendStatusMessage("Compressing data...");
|
||||||
const inpArray = new Uint8Array(input);
|
const inpArray = new Uint8Array(input);
|
||||||
const bzip2cc = bzip2.compressBZ2(inpArray, blockSize, workFactor);
|
const bzip2cc = bzip2.compressBZ2(inpArray, blockSize, workFactor);
|
||||||
if (bzip2cc.error !== 0) {
|
if (bzip2cc.error !== 0) {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import Bzip2 from "libbzip2-wasm";
|
import Bzip2 from "libbzip2-wasm";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bzip2 Decompress operation
|
* Bzip2 Decompress operation
|
||||||
|
@ -51,10 +52,10 @@ class Bzip2Decompress extends Operation {
|
||||||
if (input.byteLength <= 0) {
|
if (input.byteLength <= 0) {
|
||||||
throw new OperationError("Please provide an input.");
|
throw new OperationError("Please provide an input.");
|
||||||
}
|
}
|
||||||
if (ENVIRONMENT_IS_WORKER()) self.sendStatusMessage("Loading Bzip2...");
|
if (isWorkerEnvironment()) self.sendStatusMessage("Loading Bzip2...");
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
Bzip2().then(bzip2 => {
|
Bzip2().then(bzip2 => {
|
||||||
if (ENVIRONMENT_IS_WORKER()) self.sendStatusMessage("Decompressing data...");
|
if (isWorkerEnvironment()) self.sendStatusMessage("Decompressing data...");
|
||||||
const inpArray = new Uint8Array(input);
|
const inpArray = new Uint8Array(input);
|
||||||
const bzip2cc = bzip2.decompressBZ2(inpArray, small ? 1 : 0);
|
const bzip2cc = bzip2.decompressBZ2(inpArray, small ? 1 : 0);
|
||||||
if (bzip2cc.error !== 0) {
|
if (bzip2cc.error !== 0) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import OperationError from "../errors/OperationError";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64";
|
import { toBase64 } from "../lib/Base64";
|
||||||
import { gaussianBlur } from "../lib/ImageManipulation";
|
import { gaussianBlur } from "../lib/ImageManipulation";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,16 +74,16 @@ class SharpenImage extends Operation {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Sharpening image... (Cloning image)");
|
self.sendStatusMessage("Sharpening image... (Cloning image)");
|
||||||
const blurMask = image.clone();
|
const blurMask = image.clone();
|
||||||
|
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Sharpening image... (Blurring cloned image)");
|
self.sendStatusMessage("Sharpening image... (Blurring cloned image)");
|
||||||
const blurImage = gaussianBlur(image.clone(), radius, 3);
|
const blurImage = gaussianBlur(image.clone(), radius, 3);
|
||||||
|
|
||||||
|
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Sharpening image... (Creating unsharp mask)");
|
self.sendStatusMessage("Sharpening image... (Creating unsharp mask)");
|
||||||
blurMask.scan(0, 0, blurMask.bitmap.width, blurMask.bitmap.height, function(x, y, idx) {
|
blurMask.scan(0, 0, blurMask.bitmap.width, blurMask.bitmap.height, function(x, y, idx) {
|
||||||
const blurRed = blurImage.bitmap.data[idx];
|
const blurRed = blurImage.bitmap.data[idx];
|
||||||
|
@ -99,7 +100,7 @@ class SharpenImage extends Operation {
|
||||||
this.bitmap.data[idx + 2] = (normalBlue > blurBlue) ? normalBlue - blurBlue : 0;
|
this.bitmap.data[idx + 2] = (normalBlue > blurBlue) ? normalBlue - blurBlue : 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Sharpening image... (Merging with unsharp mask)");
|
self.sendStatusMessage("Sharpening image... (Merging with unsharp mask)");
|
||||||
image.scan(0, 0, image.bitmap.width, image.bitmap.height, function(x, y, idx) {
|
image.scan(0, 0, image.bitmap.width, image.bitmap.height, function(x, y, idx) {
|
||||||
let maskRed = blurMask.bitmap.data[idx];
|
let maskRed = blurMask.bitmap.data[idx];
|
||||||
|
|
|
@ -215,8 +215,8 @@ Full hash: $2a$10$ODeP1.6fMsb.ENk2ngPUCO7qTGVPyHA9TqDVcyupyed8FjsiF65L6`;
|
||||||
}`);
|
}`);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
it("Bzip2 Decompress", () => {
|
it("Bzip2 Decompress", async () => {
|
||||||
const result = chef.bzip2Decompress(chef.fromBase64("QlpoOTFBWSZTWUdQlt0AAAIVgEAAAQAmJAwAIAAxBkxA0A2pTL6U2CozxdyRThQkEdQlt0A="));
|
const result = await chef.bzip2Decompress(chef.fromBase64("QlpoOTFBWSZTWUdQlt0AAAIVgEAAAQAmJAwAIAAxBkxA0A2pTL6U2CozxdyRThQkEdQlt0A="));
|
||||||
assert.strictEqual(result.toString(), "Fit as a Fiddle");
|
assert.strictEqual(result.toString(), "Fit as a Fiddle");
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* @copyright Crown Copyright 2019
|
* @copyright Crown Copyright 2019
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
import TestRegister from "../TestRegister";
|
import TestRegister from "../../lib/TestRegister";
|
||||||
|
|
||||||
TestRegister.addTests([
|
TestRegister.addTests([
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* @copyright Crown Copyright 2019
|
* @copyright Crown Copyright 2019
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
import TestRegister from "../TestRegister";
|
import TestRegister from "../../lib/TestRegister";
|
||||||
|
|
||||||
const EXPECTED_CSV_SINGLE = "a,b,c\r\n1,2,3\r\n";
|
const EXPECTED_CSV_SINGLE = "a,b,c\r\n1,2,3\r\n";
|
||||||
const EXPECTED_CSV_MULTIPLE = "a,b,c\r\n1,2,3\r\n1,2,3\r\n";
|
const EXPECTED_CSV_MULTIPLE = "a,b,c\r\n1,2,3\r\n1,2,3\r\n";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue