mirror of
https://github.com/gchq/CyberChef.git
synced 2025-06-14 10:14:53 -04:00
Merge 5f185a3648
into c57556f49f
This commit is contained in:
commit
d8360d4da0
3 changed files with 83 additions and 9 deletions
|
@ -25,7 +25,13 @@ class JWTDecode extends Operation {
|
||||||
this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token";
|
this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token";
|
||||||
this.inputType = "string";
|
this.inputType = "string";
|
||||||
this.outputType = "JSON";
|
this.outputType = "JSON";
|
||||||
this.args = [];
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "Include header",
|
||||||
|
type: "boolean",
|
||||||
|
value: false
|
||||||
|
}
|
||||||
|
];
|
||||||
this.checks = [
|
this.checks = [
|
||||||
{
|
{
|
||||||
pattern: "^ey([A-Za-z0-9_-]+)\\.ey([A-Za-z0-9_-]+)\\.([A-Za-z0-9_-]+)$",
|
pattern: "^ey([A-Za-z0-9_-]+)\\.ey([A-Za-z0-9_-]+)\\.([A-Za-z0-9_-]+)$",
|
||||||
|
@ -42,12 +48,17 @@ class JWTDecode extends Operation {
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
try {
|
try {
|
||||||
|
const headerInclude = args[0];
|
||||||
|
|
||||||
const decoded = jwt.decode(input, {
|
const decoded = jwt.decode(input, {
|
||||||
json: true,
|
json: true,
|
||||||
complete: true
|
complete: true
|
||||||
});
|
});
|
||||||
|
if (headerInclude) {
|
||||||
return decoded.payload;
|
return {header: decoded.header, payload: decoded.payload};
|
||||||
|
} else {
|
||||||
|
return decoded.payload;
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new OperationError(err);
|
throw new OperationError(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,5 +47,68 @@ TestRegister.addTests([
|
||||||
args: [],
|
args: [],
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "JWT Decode: HS",
|
||||||
|
input: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.0ha6-j4FwvEIKPVZ-hf3S_R9Hy_UtXzq4dnedXcUrXk",
|
||||||
|
expectedOutput: JSON.stringify({
|
||||||
|
header: {
|
||||||
|
alg: "HS256",
|
||||||
|
typ: "JWT"
|
||||||
|
},
|
||||||
|
payload: {
|
||||||
|
String: "SomeString",
|
||||||
|
Number: 42,
|
||||||
|
iat: 1
|
||||||
|
}
|
||||||
|
}, null, 4),
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "JWT Decode",
|
||||||
|
args: [true],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "JWT Decode: RS",
|
||||||
|
input: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.MjEJhtZk2nXzigi24piMzANmrj3mILHJcDl0xOjl5a8EgdKVL1oaMEjTkMQp5RA8YrqeRBFaX-BGGCKOXn5zPY1DJwWsBUyN9C-wGR2Qye0eogH_3b4M9EW00TPCUPXm2rx8URFj7Wg9VlsmrGzLV2oKkPgkVxuFSxnpO3yjn1Y",
|
||||||
|
expectedOutput: JSON.stringify({
|
||||||
|
header: {
|
||||||
|
alg: "RS256",
|
||||||
|
typ: "JWT"
|
||||||
|
},
|
||||||
|
payload: {
|
||||||
|
String: "SomeString",
|
||||||
|
Number: 42,
|
||||||
|
iat: 1
|
||||||
|
}
|
||||||
|
}, null, 4),
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "JWT Decode",
|
||||||
|
args: [true],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "JWT Decode: ES",
|
||||||
|
input: "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.WkECT51jSfpRkcpQ4x0h5Dwe7CFBI6u6Et2gWp91HC7mpN_qCFadRpsvJLtKubm6cJTLa68xtei0YrDD8fxIUA",
|
||||||
|
expectedOutput: JSON.stringify({
|
||||||
|
header: {
|
||||||
|
alg: "ES256",
|
||||||
|
typ: "JWT"
|
||||||
|
},
|
||||||
|
payload: {
|
||||||
|
String: "SomeString",
|
||||||
|
Number: 42,
|
||||||
|
iat: 1
|
||||||
|
}
|
||||||
|
}, null, 4),
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "JWT Decode",
|
||||||
|
args: [true],
|
||||||
|
}
|
||||||
|
],
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -92,7 +92,7 @@ TestRegister.addTests([
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
args: []
|
args: [false]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -107,7 +107,7 @@ TestRegister.addTests([
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
args: []
|
args: [false]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -122,7 +122,7 @@ TestRegister.addTests([
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
args: []
|
args: [false]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -137,7 +137,7 @@ TestRegister.addTests([
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
args: []
|
args: [false]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -152,7 +152,7 @@ TestRegister.addTests([
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
args: []
|
args: [false]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -167,7 +167,7 @@ TestRegister.addTests([
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
args: []
|
args: [false]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue