{"id":1079,"library":"jwcrypto","title":"jwcrypto: JOSE Web Standards Implementation","description":"JWCrypto is a Python library that implements the Javascript Object Signing and Encryption (JOSE) Web Standards, including JSON Web Key (JWK), JSON Web Signature (JWS), JSON Web Encryption (JWE), and JSON Web Token (JWT). It leverages the `cryptography` package for its underlying cryptographic functions, ensuring strong security. The library is actively maintained, with frequent releases addressing security vulnerabilities and compatibility, currently at version 1.5.6.","status":"active","version":"1.5.6","language":"en","source_language":"en","source_url":"https://github.com/latchset/jwcrypto","tags":["security","cryptography","jose","jwt","jwe","jws","jwk","authentication","authorization"],"install":[{"cmd":"pip install jwcrypto","lang":"bash","label":"Install jwcrypto"}],"dependencies":[{"reason":"Core cryptographic operations are delegated to this library.","package":"cryptography","optional":false},{"reason":"Used for backported and experimental type hints.","package":"typing_extensions","optional":false}],"imports":[{"symbol":"JWK","correct":"from jwcrypto import jwk"},{"symbol":"JWS","correct":"from jwcrypto import jws"},{"symbol":"JWE","correct":"from jwcrypto import jwe"},{"symbol":"JWT","correct":"from jwcrypto import jwt"},{"symbol":"json_encode, json_decode","correct":"from jwcrypto.common import json_encode, json_decode"}],"quickstart":{"code":"from jwcrypto import jwk, jws\nfrom jwcrypto.common import json_encode\n\n# 1. Generate a symmetric key\nkey = jwk.JWK.generate(kty='oct', size=256)\n\n# 2. Define the payload and JWS headers\npayload = \"My Integrity protected message\"\njwstoken = jws.JWS(payload.encode('utf-8'))\n\n# 3. Add signature to the token\njwstoken.add_signature(\n    key,\n    None,\n    json_encode({\"alg\": \"HS256\"}),\n    json_encode({\"kid\": key.thumbprint()})\n)\n\n# 4. Serialize the JWS token\nsigned_token = jwstoken.serialize()\nprint(f\"Signed JWS: {signed_token}\")\n\n# 5. Verify the JWS token\nverifier_token = jws.JWS()\nverifier_token.deserialize(signed_token)\nverifier_token.verify(key)\n\n# 6. Access the verified payload\nverified_payload = verifier_token.payload.decode('utf-8')\nprint(f\"Verified Payload: {verified_payload}\")","lang":"python","description":"This quickstart demonstrates how to generate a symmetric key, sign a payload using JWS, and then verify the signed token. It utilizes `jwk` for key management and `jws` for signature operations, along with `jwcrypto.common` for JSON encoding."},"warnings":[{"fix":"Explicitly set the `expect_type` argument in `jwt.JWT` validation, or ensure that only appropriate algorithms are used to prevent type confusion. A 'born-deprecated' module-level variable can temporarily restore old behavior, but refactoring is strongly recommended.","message":"The JWT module introduced security fixes in v1.4.0 (CVE-2022-3102) that prevent token type substitution attacks. This required changes to token validation, defaulting to 'JWS' unless explicitly set or inferred. Old applications might break if they relied on implicit auto-detection without specifying `expect_type` or allowing mixed-type tokens.","severity":"breaking","affected_versions":">=1.4.0"},{"fix":"Avoid using `RSA1_5`. If absolutely necessary, it requires explicit re-enabling at object instantiation. Consider migrating to `RSA-OAEP` or `RSASSA-PSS` for secure RSA operations.","message":"The `RSA1_5` algorithm is considered deprecated due to severe security vulnerabilities (Bleichenbacher RSA padding oracle, Million messages attack). Using it can lead to decryption of intercepted messages or forging signatures.","severity":"deprecated","affected_versions":"All versions, deprecated since 2020.12.11"},{"fix":"Upgrade your Python environment to version 3.8 or newer to ensure compatibility and receive continued updates and security patches.","message":"Support for Python 3.6 and 3.7 was dropped starting with version 1.5.3. Installations on these Python versions will likely encounter compatibility issues.","severity":"breaking","affected_versions":">=1.5.3"},{"fix":"Ensure `cryptography>=3.4` is installed. `pip install --upgrade cryptography` can resolve this.","message":"The minimum required version for the `cryptography` library was raised to 3.4 in `jwcrypto` v1.5.0. Older versions of `cryptography` will cause dependency resolution failures or runtime errors.","severity":"breaking","affected_versions":">=1.5.0"},{"fix":"Never store sensitive, confidential, or personally identifiable information (PII) directly in a JWT payload. Use JWE (JSON Web Encryption) if the content needs to be confidential, or store sensitive data securely on the server and use the JWT to reference it.","message":"JWT payloads are base64-encoded, not encrypted. This means anyone with the token can easily decode and read its contents. Storing sensitive information directly in a JWT payload is a major security risk.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement strict validation of the `kid` parameter to ensure it corresponds to an expected key from a trusted source. Do not allow arbitrary `kid` values to dictate key selection without proper authorization.","message":"Lack of proper validation for the `kid` (Key ID) header parameter can lead to key confusion attacks, where an attacker might influence which key is used for verification.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to the latest version of `jwcrypto` (1.5.6 or newer) to patch these potential DoS vectors and ensure your application is protected against these specific attacks.","message":"Versions 1.5.1 and 1.5.6 addressed potential Denial of Service (DoS) vulnerabilities related to PBKDF2 symmetric keys (v1.5.1) and high compression ratios (v1.5.6). Older versions might be susceptible.","severity":"gotcha","affected_versions":"<1.5.1 and <1.5.6"}],"env_vars":null,"last_verified":"2026-04-05T00:00:00.000Z","next_check":"2026-07-04T00:00:00.000Z"}