From 98fc9837d5d93896b0227ffd418a2ab46fa6c67e Mon Sep 17 00:00:00 2001 From: David Perry Date: Fri, 29 May 2020 15:55:12 -0400 Subject: [PATCH 1/2] Add /operations endpoint to list available operations This is a straightforward change to add a `/operations` endpoint which can be used to get a list of the available operations on the CyberChef server. The returned object has an attribute for each operation name, with the argument description as its value. This change also documents this new endpoint in `README.md` and `swagger.yml`. --- README.md | 48 +++++++++++++++++++++++++++++++++++- app.js | 2 ++ routes/operations.js | 16 ++++++++++++ swagger.yml | 58 +++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 routes/operations.js diff --git a/README.md b/README.md index fa25820..59a796d 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ A Docker image can be built, then run by doing the following: ## API overview > For full documentation of the API, you can find the swagger page hosted at the root url. See [Installing](#Installing) to run the application and browse the docs. -Currently the server just has one endpoint: `/bake`. This endpoint accepts a POST request with the following body: +The most important endpoint is `/bake`. This endpoint accepts a POST request with the following body: |Parameter|Type|Description| |---|---|---| @@ -160,6 +160,52 @@ Response: } ``` +There is also a `/operations` endpoint. This endpoint accepts a GET request and responds with a JSON object listing the available operations on this server. Each operation name is one attribute, and its value is the description of the arguments it can take. + +#### Example: operation list +Response: +```javascript +{ + "FromBase64" : { + "alphabet" : { + "type" : "editableOption", + "options" : [ + { + "name" : "Standard (RFC 4648): A-Za-z0-9+/=", + "value" : "A-Za-z0-9+/=" + }, + { + "name" : "URL safe (RFC 4648 §5): A-Za-z0-9-_", + "value" : "A-Za-z0-9-_" + }, + [...] + ] + }, + "removeNon-alphabetChars" : { + "type" : "boolean", + "value" : true + } + }, + "ToBase64" : { + "alphabet" : { + "type" : "editableOption", + "options" : [ + { + "name" : "Standard (RFC 4648): A-Za-z0-9+/=", + "value" : "A-Za-z0-9+/=" + }, + { + "name" : "URL safe (RFC 4648 §5): A-Za-z0-9-_", + "value" : "A-Za-z0-9-_" + }, + [...] + ] + } + }, + [...] +} +``` + ## Licencing CyberChef-server is released under the [Apache 2.0 Licence](https://www.apache.org/licenses/LICENSE-2.0) and is covered by [Crown Copyright](https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/copyright-and-re-use/crown-copyright/). diff --git a/app.js b/app.js index 62fda22..002f97b 100644 --- a/app.js +++ b/app.js @@ -10,6 +10,7 @@ import errorHandler from "./lib/errorHandler.js"; import helmet from "helmet"; import bakeRouter from "./routes/bake"; +import operationsRouter from "./routes/operations"; const app = express(); app.disable("x-powered-by"); @@ -37,6 +38,7 @@ const swaggerFile = fs.readFileSync("./swagger.yml", "utf8"); // Routes app.use("/bake", bakeRouter); +app.use("/operations", operationsRouter); // Default route diff --git a/routes/operations.js b/routes/operations.js new file mode 100644 index 0000000..7064c7b --- /dev/null +++ b/routes/operations.js @@ -0,0 +1,16 @@ +import { Router } from "express"; +const router = Router(); +import { operations } from "cyberchef/src/node/index.mjs"; + +/** + * operationsGet + */ +router.get("/", async (req, res, next) => { + const ret = {}; + for (let op of operations) { + if (op.opName) ret[op.opName] = op.args; + } + res.send(ret); +}); + +export default router; diff --git a/swagger.yml b/swagger.yml index c54ca0d..5686f57 100644 --- a/swagger.yml +++ b/swagger.yml @@ -6,6 +6,62 @@ info: paths: + /operations: + get: + summary: List available operations + description: > + Retrieve a list of all available operations on this server. + The return value is an object whose attributes are operation names, + and each attribute value is the description of the arguments + the argument takes. + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + example: > + { + "FromBase64" : { + "alphabet" : { + "type" : "editableOption", + "options" : [ + { + "name" : "Standard (RFC 4648): A-Za-z0-9+/=", + "value" : "A-Za-z0-9+/=" + }, + { + "name" : "URL safe (RFC 4648 §5): A-Za-z0-9-_", + "value" : "A-Za-z0-9-_" + }, + [...] + ] + }, + "removeNon-alphabetChars" : { + "type" : "boolean", + "value" : true + } + }, + "ToBase64" : { + "alphabet" : { + "type" : "editableOption", + "options" : [ + { + "name" : "Standard (RFC 4648): A-Za-z0-9+/=", + "value" : "A-Za-z0-9+/=" + }, + { + "name" : "URL safe (RFC 4648 §5): A-Za-z0-9-_", + "value" : "A-Za-z0-9-_" + }, + [...] + ] + } + }, + [...] + } + /bake: post: summary: Bakes a recipe @@ -99,4 +155,4 @@ components: width: 16 upperCaseHex: true includeFinalLength: false - \ No newline at end of file + From 16c9494d6a473c6a6636a6e0eff8386cc1eed775 Mon Sep 17 00:00:00 2001 From: David Perry Date: Fri, 29 May 2020 16:01:19 -0400 Subject: [PATCH 2/2] Ran eslint --- routes/operations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/operations.js b/routes/operations.js index 7064c7b..ff0fc1c 100644 --- a/routes/operations.js +++ b/routes/operations.js @@ -7,7 +7,7 @@ import { operations } from "cyberchef/src/node/index.mjs"; */ router.get("/", async (req, res, next) => { const ret = {}; - for (let op of operations) { + for (const op of operations) { if (op.opName) ret[op.opName] = op.args; } res.send(ret);