mirror of
https://github.com/gchq/CyberChef.git
synced 2025-06-15 10:44:50 -04:00
Add possibility to show/hide human readable dates based on given timestamps of jwt token.
This commit is contained in:
parent
c57556f49f
commit
291a278dfa
2 changed files with 44 additions and 4 deletions
|
@ -7,6 +7,7 @@
|
|||
import Operation from "../Operation.mjs";
|
||||
import jwt from "jsonwebtoken";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import moment from "moment-timezone";
|
||||
|
||||
/**
|
||||
* JWT Decode operation
|
||||
|
@ -25,7 +26,13 @@ class JWTDecode extends Operation {
|
|||
this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token";
|
||||
this.inputType = "string";
|
||||
this.outputType = "JSON";
|
||||
this.args = [];
|
||||
this.args = [
|
||||
{
|
||||
"name": "Show/Hide dates",
|
||||
"type": "boolean",
|
||||
"value": false
|
||||
}
|
||||
];
|
||||
this.checks = [
|
||||
{
|
||||
pattern: "^ey([A-Za-z0-9_-]+)\\.ey([A-Za-z0-9_-]+)\\.([A-Za-z0-9_-]+)$",
|
||||
|
@ -42,11 +49,27 @@ class JWTDecode extends Operation {
|
|||
*/
|
||||
run(input, args) {
|
||||
try {
|
||||
const formatAsDate = args[0];
|
||||
const decoded = jwt.decode(input, {
|
||||
json: true,
|
||||
complete: true
|
||||
});
|
||||
|
||||
if (formatAsDate) {
|
||||
const payload = {...decoded.payload};
|
||||
if (payload.iat) {
|
||||
payload.iat = payload.iat + " ("+moment.unix(payload.iat).tz("UTC").format("ddd D MMMM YYYY HH:mm:ss") + " UTC)";
|
||||
}
|
||||
if (payload.exp) {
|
||||
payload.exp = payload.exp + " ("+moment.unix(payload.exp).tz("UTC").format("ddd D MMMM YYYY HH:mm:ss") + " UTC)";
|
||||
}
|
||||
if (payload.nbf) {
|
||||
payload.nbf = payload.nbf + " ("+moment.unix(payload.nbf).tz("UTC").format("ddd D MMMM YYYY HH:mm:ss") + " UTC)";
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
return decoded.payload;
|
||||
} catch (err) {
|
||||
throw new OperationError(err);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue