JSON Web Token (JWT) is an open standard that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. JWT is a generic name for the following types of token:
JSON Web Signature (JWS): The payload is encoded and signed so the integrity of the claims can be verified.
JSON Web Encryption (JWE): The payload is encrypted so the claims are hidden from other parties.
The image was extracted from this page.
Is the correct thing to do something like this? JWS(JWE('hello world')
with the encrypted JWE as the payload of the JWS?
It's a nested JWT and its concept is defined in the RFC 7519:
A JWT in which nested signing and/or encryption are employed. In
Nested JWTs, a JWT is used as the payload or plaintext value of an
enclosing JWS or JWE structure, respectively.
You could add a JWE as a claim of a JWS payload, however the other way around is recommended: First sign the message and then encrypt the result, as mentioned in the same document:
11.2. Signing and Encryption Order
While syntactically the signing and encryption operations for Nested
JWTs may be applied in any order, if both signing and encryption are
necessary, normally producers should sign the message and then
encrypt the result (thus encrypting the signature). This prevents
attacks in which the signature is stripped, leaving just an encrypted
message, as well as providing privacy for the signer. Furthermore,
signatures over encrypted text are not considered valid in many
jurisdictions.
JWE(JWS(payload))
). See tools.ietf.org/html/rfc7519#section-11.2 for details. – HeligolandJWS(JWE(payload))
. 1) the JWS can completely be removed and replaced by another (malicious) one. 2) JWS header is visible and may leak information. – HeligolandJWE(JWS(payload))
butJWS(JWE(payload))
is pretty straightforward – Heligoland