mirror of
https://github.com/gchq/CyberChef
synced 2024-12-27 04:53:16 +00:00
Fixed 'Parse URI' operation and improved error handling from worker
This commit is contained in:
parent
ec7294d734
commit
599fefb39b
9 changed files with 61 additions and 56 deletions
|
@ -68,9 +68,10 @@ Chef.prototype.bake = async function(inputText, recipeConfig, options, progress,
|
||||||
try {
|
try {
|
||||||
progress = await recipe.execute(this.dish, progress);
|
progress = await recipe.execute(this.dish, progress);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Return the error in the result so that everything else gets correctly updated
|
console.log(err);
|
||||||
// rather than throwing it here and losing state info.
|
error = {
|
||||||
error = err;
|
displayStr: err.displayStr,
|
||||||
|
};
|
||||||
progress = err.progress;
|
progress = err.progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -760,14 +760,14 @@ const OperationConfig = {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"URL Decode": {
|
"URL Decode": {
|
||||||
module: "Default",
|
module: "URL",
|
||||||
description: "Converts URI/URL percent-encoded characters back to their raw values.<br><br>e.g. <code>%3d</code> becomes <code>=</code>",
|
description: "Converts URI/URL percent-encoded characters back to their raw values.<br><br>e.g. <code>%3d</code> becomes <code>=</code>",
|
||||||
inputType: "string",
|
inputType: "string",
|
||||||
outputType: "string",
|
outputType: "string",
|
||||||
args: []
|
args: []
|
||||||
},
|
},
|
||||||
"URL Encode": {
|
"URL Encode": {
|
||||||
module: "Default",
|
module: "URL",
|
||||||
description: "Encodes problematic characters into percent-encoding, a format supported by URIs/URLs.<br><br>e.g. <code>=</code> becomes <code>%3d</code>",
|
description: "Encodes problematic characters into percent-encoding, a format supported by URIs/URLs.<br><br>e.g. <code>=</code> becomes <code>%3d</code>",
|
||||||
inputType: "string",
|
inputType: "string",
|
||||||
outputType: "string",
|
outputType: "string",
|
||||||
|
@ -780,7 +780,7 @@ const OperationConfig = {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"Parse URI": {
|
"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.",
|
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",
|
inputType: "string",
|
||||||
outputType: "string",
|
outputType: "string",
|
||||||
|
|
|
@ -26,7 +26,6 @@ import SeqUtils from "../../operations/SeqUtils.js";
|
||||||
import StrUtils from "../../operations/StrUtils.js";
|
import StrUtils from "../../operations/StrUtils.js";
|
||||||
import Tidy from "../../operations/Tidy.js";
|
import Tidy from "../../operations/Tidy.js";
|
||||||
import Unicode from "../../operations/Unicode.js";
|
import Unicode from "../../operations/Unicode.js";
|
||||||
import URL_ from "../../operations/URL.js";
|
|
||||||
import UUID from "../../operations/UUID.js";
|
import UUID from "../../operations/UUID.js";
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,9 +76,6 @@ OpModules.Default = {
|
||||||
"From HTML Entity": HTML.runFromEntity,
|
"From HTML Entity": HTML.runFromEntity,
|
||||||
"Strip HTML tags": HTML.runStripTags,
|
"Strip HTML tags": HTML.runStripTags,
|
||||||
"Parse colour code": HTML.runParseColourCode,
|
"Parse colour code": HTML.runParseColourCode,
|
||||||
"URL Encode": URL_.runTo,
|
|
||||||
"URL Decode": URL_.runFrom,
|
|
||||||
"Parse URI": URL_.runParse,
|
|
||||||
"Unescape Unicode Characters": Unicode.runUnescape,
|
"Unescape Unicode Characters": Unicode.runUnescape,
|
||||||
"To Quoted Printable": QuotedPrintable.runTo,
|
"To Quoted Printable": QuotedPrintable.runTo,
|
||||||
"From Quoted Printable": QuotedPrintable.runFrom,
|
"From Quoted Printable": QuotedPrintable.runFrom,
|
||||||
|
|
|
@ -19,6 +19,7 @@ import ImageModule from "./Image.js";
|
||||||
import JSBNModule from "./JSBN.js";
|
import JSBNModule from "./JSBN.js";
|
||||||
import PublicKeyModule from "./PublicKey.js";
|
import PublicKeyModule from "./PublicKey.js";
|
||||||
import ShellcodeModule from "./Shellcode.js";
|
import ShellcodeModule from "./Shellcode.js";
|
||||||
|
import URLModule from "./URL.js";
|
||||||
|
|
||||||
Object.assign(
|
Object.assign(
|
||||||
OpModules,
|
OpModules,
|
||||||
|
@ -33,7 +34,8 @@ Object.assign(
|
||||||
ImageModule,
|
ImageModule,
|
||||||
JSBNModule,
|
JSBNModule,
|
||||||
PublicKeyModule,
|
PublicKeyModule,
|
||||||
ShellcodeModule
|
ShellcodeModule,
|
||||||
|
URLModule
|
||||||
);
|
);
|
||||||
|
|
||||||
export default OpModules;
|
export default OpModules;
|
||||||
|
|
23
src/core/config/modules/URL.js
Normal file
23
src/core/config/modules/URL.js
Normal file
|
@ -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;
|
|
@ -1,5 +1,6 @@
|
||||||
/* globals unescape */
|
/* globals unescape */
|
||||||
import Utils from "../Utils.js";
|
import Utils from "../Utils.js";
|
||||||
|
import url from "url";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,56 +59,36 @@ const URL_ = {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runParse: function(input, args) {
|
runParse: function(input, args) {
|
||||||
if (!document) {
|
const uri = url.parse(input, true);
|
||||||
throw "This operation only works in a browser.";
|
|
||||||
}
|
|
||||||
|
|
||||||
const a = document.createElement("a");
|
|
||||||
|
|
||||||
// Overwrite base href which will be the current CyberChef URL to reduce confusion.
|
|
||||||
a.href = "http://example.com/";
|
|
||||||
a.href = input;
|
|
||||||
|
|
||||||
if (a.protocol) {
|
|
||||||
let output = "";
|
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";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a.pathname && a.pathname !== window.location.pathname) {
|
if (uri.protocol) output += "Protocol:\t" + uri.protocol + "\n";
|
||||||
let pathname = a.pathname;
|
if (uri.auth) output += "Auth:\t\t" + uri.auth + "\n";
|
||||||
if (pathname.indexOf(window.location.pathname) === 0)
|
if (uri.hostname) output += "Hostname:\t" + uri.hostname + "\n";
|
||||||
pathname = pathname.replace(window.location.pathname, "");
|
if (uri.port) output += "Port:\t\t" + uri.port + "\n";
|
||||||
if (pathname)
|
if (uri.pathname) output += "Path name:\t" + uri.pathname + "\n";
|
||||||
output += "Path name:\t" + pathname + "\n";
|
if (uri.query) {
|
||||||
}
|
let keys = Object.keys(uri.query),
|
||||||
|
padding = 0;
|
||||||
|
|
||||||
if (a.hash && a.hash !== window.location.hash) {
|
keys.forEach(k => {
|
||||||
output += "Hash:\t\t" + a.hash + "\n";
|
padding = (k.length > padding) ? k.length : padding;
|
||||||
}
|
});
|
||||||
|
|
||||||
if (a.search && a.search !== window.location.search) {
|
|
||||||
output += "Arguments:\n";
|
output += "Arguments:\n";
|
||||||
const args_ = (a.search.slice(1, a.search.length)).split("&");
|
for (let key in uri.query) {
|
||||||
let splitArgs = [], padding = 0, i;
|
output += "\t" + Utils.padRight(key, padding);
|
||||||
for (i = 0; i < args_.length; i++) {
|
if (uri.query[key].length) {
|
||||||
splitArgs.push(args_[i].split("="));
|
output += " = " + uri.query[key] + "\n";
|
||||||
padding = (splitArgs[i][0].length > padding) ? splitArgs[i][0].length : padding;
|
} else {
|
||||||
}
|
output += "\n";
|
||||||
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";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (uri.hash) output += "Hash:\t\t" + uri.hash + "\n";
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
|
||||||
|
|
||||||
return "Invalid URI";
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -88,9 +88,10 @@ App.prototype.loaded = function() {
|
||||||
* An error handler for displaying the error to the user.
|
* An error handler for displaying the error to the user.
|
||||||
*
|
*
|
||||||
* @param {Error} err
|
* @param {Error} err
|
||||||
|
* @param {boolean} [logToConsole=false]
|
||||||
*/
|
*/
|
||||||
App.prototype.handleError = function(err) {
|
App.prototype.handleError = function(err, logToConsole) {
|
||||||
console.error(err);
|
if (logToConsole) console.error(err);
|
||||||
const msg = err.displayStr || err.toString();
|
const msg = err.displayStr || err.toString();
|
||||||
this.alert(msg, "danger", this.options.errorTimeout, !this.options.showErrors);
|
this.alert(msg, "danger", this.options.errorTimeout, !this.options.showErrors);
|
||||||
};
|
};
|
||||||
|
|
|
@ -382,7 +382,7 @@
|
||||||
<p>Released under the Apache Licence, Version 2.0.</p>
|
<p>Released under the Apache Licence, Version 2.0.</p>
|
||||||
<p>
|
<p>
|
||||||
<a href="https://gitter.im/gchq/CyberChef">
|
<a href="https://gitter.im/gchq/CyberChef">
|
||||||
<img src="https://badges.gitter.im/gchq/CyberChef.svg">
|
<img src="<%- require('../static/images/gitter-badge.svg') %>">
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
<br>
|
<br>
|
||||||
|
|
1
src/web/static/images/gitter-badge.svg
Executable file
1
src/web/static/images/gitter-badge.svg
Executable file
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="92" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="92" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h34v20H0z"/><path fill="#46BC99" d="M34 0h58v20H34z"/><path fill="url(#b)" d="M0 0h92v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="17" y="15" fill="#010101" fill-opacity=".3">chat</text><text x="17" y="14">chat</text><text x="62" y="15" fill="#010101" fill-opacity=".3">on gitter</text><text x="62" y="14">on gitter</text></g></svg>
|
After Width: | Height: | Size: 733 B |
Loading…
Reference in a new issue