mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-23 00:06:17 -04:00
Add 'header' ingredient to JWT Sign operation
Expose the 'header' option of the jsonwebtoken module [1] as an ingredient. This allows for adding and overwriting JWT header fields such as 'type' or 'kid'. [1]: https://github.com/auth0/node-jsonwebtoken?tab=readme-ov-file#usage
This commit is contained in:
parent
3822c6c520
commit
71c8c8aac0
2 changed files with 28 additions and 11 deletions
|
@ -36,6 +36,11 @@ class JWTSign extends Operation {
|
|||
name: "Signing algorithm",
|
||||
type: "option",
|
||||
value: JWT_ALGORITHMS
|
||||
},
|
||||
{
|
||||
name: "Header",
|
||||
type: "text",
|
||||
value: "{}"
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -46,11 +51,12 @@ class JWTSign extends Operation {
|
|||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const [key, algorithm] = args;
|
||||
const [key, algorithm, header] = args;
|
||||
|
||||
try {
|
||||
return jwt.sign(input, key, {
|
||||
algorithm: algorithm === "None" ? "none" : algorithm
|
||||
algorithm: algorithm === "None" ? "none" : algorithm,
|
||||
header: JSON.parse(header || "{}")
|
||||
});
|
||||
} catch (err) {
|
||||
throw new OperationError(`Error: Have you entered the key correctly? The key should be either the secret for HMAC algorithms or the PEM-encoded private key for RSA and ECDSA.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue