Fix formatting and trailing whitespace

This commit is contained in:
ThePlayer372 2026-02-26 14:51:32 +01:00
parent da59efa23a
commit f784e45d86
4 changed files with 19 additions and 19 deletions

View File

@ -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];

View File

@ -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());

View File

@ -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 {

View File

@ -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([
}
]
},
])
]);