diff --git a/src/core/operations/FlaskSessionDecode.mjs b/src/core/operations/FlaskSessionDecode.mjs index 2622880c..304b99e2 100644 --- a/src/core/operations/FlaskSessionDecode.mjs +++ b/src/core/operations/FlaskSessionDecode.mjs @@ -5,7 +5,7 @@ import Operation from "../Operation.mjs"; import OperationError from "../errors/OperationError.mjs"; -import { fromBase64 } from "../lib/Base64.mjs" +import { fromBase64 } from "../lib/Base64.mjs"; /** * Flask Session Decode operation @@ -17,9 +17,9 @@ class FlaskSessionDecode extends Operation { constructor() { super(); - this.name = "Flask Session Decode"; + this.name = "Flask Session Decode"; this.module = "Crypto"; - this.description = "Decodes the payload of a Flask session cookie (itsdangerous) into JSON."; + this.description = "Decodes the payload of a Flask session cookie (itsdangerous) into JSON."; this.inputType = "string"; this.outputType = "JSON"; this.args = []; @@ -34,7 +34,7 @@ class FlaskSessionDecode extends Operation { input = input.trim(); const parts = input.split("."); if (parts.length !== 3) { - throw new OperationError("Invalid Flask token format. Expected payload.timestamp.signature"); + throw new OperationError("Invalid Flask token format. Expected payload.timestamp.signature"); } const payloadB64 = parts[0]; diff --git a/src/core/operations/FlaskSessionSign.mjs b/src/core/operations/FlaskSessionSign.mjs index c534389e..01ee8b1d 100644 --- a/src/core/operations/FlaskSessionSign.mjs +++ b/src/core/operations/FlaskSessionSign.mjs @@ -69,13 +69,13 @@ class FlaskSessionSign extends Operation { const view = new DataView(buffer); view.setInt32(0, currentTimeStamp, false); const bytes = new Uint8Array(buffer); - let binary = ''; + let binary = ""; bytes.forEach(b => binary += String.fromCharCode(b)); const timeB64 = toBase64(Utils.strToByteArray(binary)); const time = timeB64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, ""); - + const data = Utils.convertToByteString(payload + "." + time, "utf8"); - const sign = CryptoApi.getHmac(derivedKey.finalize(), CryptoApi.getHasher(algorithm)); + const sign = CryptoApi.getHmac(derivedKey.finalize(), CryptoApi.getHasher(algorithm)); sign.update(data); const signB64 = toBase64(sign.finalize()); diff --git a/src/core/operations/FlaskSessionVerify.mjs b/src/core/operations/FlaskSessionVerify.mjs index e776dbe9..2399b8ae 100644 --- a/src/core/operations/FlaskSessionVerify.mjs +++ b/src/core/operations/FlaskSessionVerify.mjs @@ -53,9 +53,9 @@ class FlaskSessionVerify extends Operation { run(input, args) { if (!args[0].string) { - throw new OperationError("Secret key required"); + throw new OperationError("Secret key required"); } - + const key = Utils.convertToByteString(args[0].string, args[0].option); const salt = Utils.convertToByteString(args[1].string || "cookie-session", args[1].option); const algorithm = args[2] || "sha1"; @@ -65,7 +65,7 @@ class FlaskSessionVerify extends Operation { const parts = input.split("."); if (parts.length !== 3) { - throw new OperationError("Invalid Flask token format. Expected payload.timestamp.signature"); + throw new OperationError("Invalid Flask token format. Expected payload.timestamp.signature"); } const data = Utils.convertToByteString(parts[0] + "." + parts[1], "utf8"); @@ -73,8 +73,8 @@ class FlaskSessionVerify extends Operation { const derivedKey = CryptoApi.getHmac(key, CryptoApi.getHasher(algorithm)); derivedKey.update(salt); - - const sign = CryptoApi.getHmac(derivedKey.finalize(), CryptoApi.getHasher(algorithm)); + + const sign = CryptoApi.getHmac(derivedKey.finalize(), CryptoApi.getHasher(algorithm)); sign.update(data); const payloadB64 = parts[0]; @@ -91,10 +91,10 @@ class FlaskSessionVerify extends Operation { const signB64 = toBase64(sign.finalize()); const sign64 = signB64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, ""); - if (sign64 !== parts[2]){ + if (sign64 !== parts[2]) { throw new OperationError("Invalid signature!"); } - + try { const decoded = JSON.parse(payloadJson); return { diff --git a/tests/operations/tests/FlaskSession.mjs b/tests/operations/tests/FlaskSession.mjs index 9edf0c4e..40271c68 100644 --- a/tests/operations/tests/FlaskSession.mjs +++ b/tests/operations/tests/FlaskSession.mjs @@ -13,12 +13,12 @@ const validKey = "mysecretkey"; const outputObject = { user: "admin", role: "superuser", -} +}; const outputVerify = { valid: true, payload: outputObject, -} +}; TestRegister.addTests([ { @@ -41,9 +41,9 @@ TestRegister.addTests([ op: "Flask Session Verify", args: [ { - string: validKey, + string: validKey, option: "UTF8" - }, + }, { string: "cookie-session", option: "UTF8" @@ -53,4 +53,4 @@ TestRegister.addTests([ } ] }, -]) \ No newline at end of file +]);