From f2b596c638080dc1bd4d00813b1d51ef967af6af Mon Sep 17 00:00:00 2001 From: n1073645 Date: Tue, 3 Dec 2019 15:03:48 +0000 Subject: [PATCH] Magic Sigs for DefangURL operation --- src/core/lib/Magic.mjs | 12 ++++++--- src/core/lib/MagicObject.mjs | 3 +-- src/core/operations/DefangURL.mjs | 43 +++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/core/lib/Magic.mjs b/src/core/lib/Magic.mjs index 3ff1821f..280d6d35 100644 --- a/src/core/lib/Magic.mjs +++ b/src/core/lib/Magic.mjs @@ -245,7 +245,7 @@ class Magic { } /** - * Uses the checks to validate the input/output of potential operations. + * Uses the checks to validate the input//output of potential operations. * * @param {string} flag * @param {array} sensible @@ -264,9 +264,13 @@ class Magic { const opConfig = { op: op.op, args: op.args - }, - output = await this._runRecipe([opConfig]); - + }; + let output; + try { + output = await this._runRecipe([opConfig]); + } catch(err) { + return; + } // If the recipe is repeating and returning the same data, do not continue if (prevOp && op.op === prevOp.op && _buffersEqual(output, this.inputBuffer)) { return; diff --git a/src/core/lib/MagicObject.mjs b/src/core/lib/MagicObject.mjs index 0c605e76..587f29c3 100644 --- a/src/core/lib/MagicObject.mjs +++ b/src/core/lib/MagicObject.mjs @@ -1,9 +1,8 @@ /** - * + * A class to make the input/output validation checks easier to define. */ class magicObject { /** - * * @param inRegexes * @param outRegexes */ diff --git a/src/core/operations/DefangURL.mjs b/src/core/operations/DefangURL.mjs index aa783c32..658dc80a 100644 --- a/src/core/operations/DefangURL.mjs +++ b/src/core/operations/DefangURL.mjs @@ -7,6 +7,7 @@ import Operation from "../Operation.mjs"; import {URL_REGEX, DOMAIN_REGEX} from "../lib/Extract.mjs"; +import magicObject from "../lib/MagicObject.mjs"; /** * DefangURL operation @@ -47,6 +48,48 @@ class DefangURL extends Operation { value: ["Valid domains and full URLs", "Only full URLs", "Everything"] } ]; + this.checks = new magicObject([ + { + match: "^\\s*(https?|ftp)://(-\\.)?([^\\s/?\\.#-]+\\.?)+(/\\S*)?\\s*$", + flags: "i", + args: [false, false, false, "Everything"], + }, + { + match: "^\\s*(https?|ftp)://(-\\.)?([^\\s/?\\.#-]+\\.?)+(/\\S*)?\\s*$", + flags: "i", + args: [true, false, false, "Everything"], + }, + { + match: "^\\s*(https?|ftp)://(-\\.)?([^\\s/?\\.#-]+\\.?)+(/\\S*)?\\s*$", + flags: "i", + args: [false, true, false, "Everything"], + }, + { + match: "^\\s*(https?|ftp)://(-\\.)?([^\\s/?\\.#-]+\\.?)+(/\\S*)?\\s*$", + flags: "i", + args: [true, true, false, "Everything"], + }, + { + match: "^\\s*(https?|ftp)://(-\\.)?([^\\s/?\\.#-]+\\.?)+(/\\S*)?\\s*$", + flags: "i", + args: [false, false, true, "Everything"], + }, + { + match: "^\\s*(https?|ftp)://(-\\.)?([^\\s/?\\.#-]+\\.?)+(/\\S*)?\\s*$", + flags: "i", + args: [true, false, true, "Everything"], + }, + { + match: "^\\s*(https?|ftp)://(-\\.)?([^\\s/?\\.#-]+\\.?)+(/\\S*)?\\s*$", + flags: "i", + args: [false, true, true, "Everything"], + }, + { + match: "^\\s*(https?|ftp)://(-\\.)?([^\\s/?\\.#-]+\\.?)+(/\\S*)?\\s*$", + flags: "i", + args: [true, true, true, "Everything"], + } + ]); } /**