diff --git a/src/core/Chef.js b/src/core/Chef.js
index 7c9817df..4e7c042a 100755
--- a/src/core/Chef.js
+++ b/src/core/Chef.js
@@ -68,9 +68,10 @@ Chef.prototype.bake = async function(inputText, recipeConfig, options, progress,
try {
progress = await recipe.execute(this.dish, progress);
} catch (err) {
- // Return the error in the result so that everything else gets correctly updated
- // rather than throwing it here and losing state info.
- error = err;
+ console.log(err);
+ error = {
+ displayStr: err.displayStr,
+ };
progress = err.progress;
}
diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js
index 06a3a2d8..9caa4f91 100755
--- a/src/core/config/OperationConfig.js
+++ b/src/core/config/OperationConfig.js
@@ -760,14 +760,14 @@ const OperationConfig = {
]
},
"URL Decode": {
- module: "Default",
+ module: "URL",
description: "Converts URI/URL percent-encoded characters back to their raw values.
e.g. %3d
becomes =
",
inputType: "string",
outputType: "string",
args: []
},
"URL Encode": {
- module: "Default",
+ module: "URL",
description: "Encodes problematic characters into percent-encoding, a format supported by URIs/URLs.
e.g. =
becomes %3d
",
inputType: "string",
outputType: "string",
@@ -780,7 +780,7 @@ const OperationConfig = {
]
},
"Parse URI": {
- module: "Default",
+ module: "URL",
description: "Pretty prints complicated Uniform Resource Identifier (URI) strings for ease of reading. Particularly useful for Uniform Resource Locators (URLs) with a lot of arguments.",
inputType: "string",
outputType: "string",
diff --git a/src/core/config/modules/Default.js b/src/core/config/modules/Default.js
index 6e51367b..682db223 100644
--- a/src/core/config/modules/Default.js
+++ b/src/core/config/modules/Default.js
@@ -26,7 +26,6 @@ import SeqUtils from "../../operations/SeqUtils.js";
import StrUtils from "../../operations/StrUtils.js";
import Tidy from "../../operations/Tidy.js";
import Unicode from "../../operations/Unicode.js";
-import URL_ from "../../operations/URL.js";
import UUID from "../../operations/UUID.js";
@@ -77,9 +76,6 @@ OpModules.Default = {
"From HTML Entity": HTML.runFromEntity,
"Strip HTML tags": HTML.runStripTags,
"Parse colour code": HTML.runParseColourCode,
- "URL Encode": URL_.runTo,
- "URL Decode": URL_.runFrom,
- "Parse URI": URL_.runParse,
"Unescape Unicode Characters": Unicode.runUnescape,
"To Quoted Printable": QuotedPrintable.runTo,
"From Quoted Printable": QuotedPrintable.runFrom,
diff --git a/src/core/config/modules/OpModules.js b/src/core/config/modules/OpModules.js
index 2d79753e..3f3963c3 100644
--- a/src/core/config/modules/OpModules.js
+++ b/src/core/config/modules/OpModules.js
@@ -19,6 +19,7 @@ import ImageModule from "./Image.js";
import JSBNModule from "./JSBN.js";
import PublicKeyModule from "./PublicKey.js";
import ShellcodeModule from "./Shellcode.js";
+import URLModule from "./URL.js";
Object.assign(
OpModules,
@@ -33,7 +34,8 @@ Object.assign(
ImageModule,
JSBNModule,
PublicKeyModule,
- ShellcodeModule
+ ShellcodeModule,
+ URLModule
);
export default OpModules;
diff --git a/src/core/config/modules/URL.js b/src/core/config/modules/URL.js
new file mode 100644
index 00000000..54bceb7c
--- /dev/null
+++ b/src/core/config/modules/URL.js
@@ -0,0 +1,23 @@
+import URL_ from "../../operations/URL.js";
+
+
+/**
+ * URL module.
+ *
+ * Libraries:
+ * - Utils.js
+ * - url
+ *
+ * @author n1474335 [n1474335@gmail.com]
+ * @copyright Crown Copyright 2017
+ * @license Apache-2.0
+ */
+let OpModules = typeof self === "undefined" ? {} : self.OpModules || {};
+
+OpModules.URL = {
+ "URL Encode": URL_.runTo,
+ "URL Decode": URL_.runFrom,
+ "Parse URI": URL_.runParse,
+};
+
+export default OpModules;
diff --git a/src/core/operations/URL.js b/src/core/operations/URL.js
index 9e00ebf8..25526f0e 100755
--- a/src/core/operations/URL.js
+++ b/src/core/operations/URL.js
@@ -1,5 +1,6 @@
/* globals unescape */
import Utils from "../Utils.js";
+import url from "url";
/**
@@ -58,56 +59,36 @@ const URL_ = {
* @returns {string}
*/
runParse: function(input, args) {
- if (!document) {
- throw "This operation only works in a browser.";
- }
+ const uri = url.parse(input, true);
- const a = document.createElement("a");
+ let output = "";
- // Overwrite base href which will be the current CyberChef URL to reduce confusion.
- a.href = "http://example.com/";
- a.href = input;
+ if (uri.protocol) output += "Protocol:\t" + uri.protocol + "\n";
+ if (uri.auth) output += "Auth:\t\t" + uri.auth + "\n";
+ if (uri.hostname) output += "Hostname:\t" + uri.hostname + "\n";
+ if (uri.port) output += "Port:\t\t" + uri.port + "\n";
+ if (uri.pathname) output += "Path name:\t" + uri.pathname + "\n";
+ if (uri.query) {
+ let keys = Object.keys(uri.query),
+ padding = 0;
- if (a.protocol) {
- let output = "";
- if (a.hostname !== window.location.hostname) {
- output = "Protocol:\t" + a.protocol + "\n";
- if (a.hostname) output += "Hostname:\t" + a.hostname + "\n";
- if (a.port) output += "Port:\t\t" + a.port + "\n";
- }
+ keys.forEach(k => {
+ padding = (k.length > padding) ? k.length : padding;
+ });
- if (a.pathname && a.pathname !== window.location.pathname) {
- let pathname = a.pathname;
- if (pathname.indexOf(window.location.pathname) === 0)
- pathname = pathname.replace(window.location.pathname, "");
- if (pathname)
- output += "Path name:\t" + pathname + "\n";
- }
-
- if (a.hash && a.hash !== window.location.hash) {
- output += "Hash:\t\t" + a.hash + "\n";
- }
-
- if (a.search && a.search !== window.location.search) {
- output += "Arguments:\n";
- const args_ = (a.search.slice(1, a.search.length)).split("&");
- let splitArgs = [], padding = 0, i;
- for (i = 0; i < args_.length; i++) {
- splitArgs.push(args_[i].split("="));
- padding = (splitArgs[i][0].length > padding) ? splitArgs[i][0].length : padding;
- }
- for (i = 0; i < splitArgs.length; i++) {
- output += "\t" + Utils.padRight(splitArgs[i][0], padding);
- if (splitArgs[i].length > 1 && splitArgs[i][1].length)
- output += " = " + splitArgs[i][1] + "\n";
- else output += "\n";
+ output += "Arguments:\n";
+ for (let key in uri.query) {
+ output += "\t" + Utils.padRight(key, padding);
+ if (uri.query[key].length) {
+ output += " = " + uri.query[key] + "\n";
+ } else {
+ output += "\n";
}
}
-
- return output;
}
+ if (uri.hash) output += "Hash:\t\t" + uri.hash + "\n";
- return "Invalid URI";
+ return output;
},
diff --git a/src/web/App.js b/src/web/App.js
index ff57a7ed..036a4fb9 100755
--- a/src/web/App.js
+++ b/src/web/App.js
@@ -88,9 +88,10 @@ App.prototype.loaded = function() {
* An error handler for displaying the error to the user.
*
* @param {Error} err
+ * @param {boolean} [logToConsole=false]
*/
-App.prototype.handleError = function(err) {
- console.error(err);
+App.prototype.handleError = function(err, logToConsole) {
+ if (logToConsole) console.error(err);
const msg = err.displayStr || err.toString();
this.alert(msg, "danger", this.options.errorTimeout, !this.options.showErrors);
};
diff --git a/src/web/html/index.html b/src/web/html/index.html
index 9378196c..5df6682c 100755
--- a/src/web/html/index.html
+++ b/src/web/html/index.html
@@ -382,7 +382,7 @@
Released under the Apache Licence, Version 2.0.