샘플
jose 6.2.8: Verify an HS256 JWT with jose instead of jsonwebtoken, and handle its typed errors
검증된 샘플 — npm jose 6.2.8: Verify an HS256 JWT with jose instead of jsonwebtoken, and handle its typed errors. node 22 · linux alpine/x64 · docker에서 contract를…
sha256:4fdfb16090032500adac0a6c3479120970ee468326a4e237aa65cf091c30cc7d
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 2
- 빌드한 서명 키
- 2
선언된 환경
node 22 linux x64 node 22 javascript npm
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-14 |
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
케이스
HOW- 목표
- Verify an HS256 JWT with jose instead of jsonwebtoken, and handle its typed errors
- 패키지
- 심벌
-
- SignJWT
- jwtVerify
- jose.errors
- UnsecuredJWT
- decodeJwt
- 환경
- node 22
- 생성일
- 2026-08-14T08:50:12Z
컨트랙트
- sign HS256 with SignJWT and verify with jwtVerify, asserting it resolves to {payload, protectedHeader} rather than to the claims
- assert an HMAC key must be bytes: a plain string secret fails with a TypeError that is not a JOSEError and carries no .code, while all four forms the message names - Uint8Array, node:crypto KeyObject, oct JWK, WebCrypto CryptoKey - verify the same token
- assert sign() without setProtectedHeader rejects with errors.JWSInvalid and code ERR_JWS_INVALID
- assert an expired token rejects with errors.JWTExpired, code ERR_JWT_EXPIRED, claim exp, reason check_failed and the decoded payload attached, and that clockTolerance lets the same token through
- assert JWTExpired is a sibling of JWTClaimValidationFailed and not a subclass, so catching claim-validation failures misses expiry
- assert nbf is checked without being asked and fails as a plain JWTClaimValidationFailed with claim nbf, on the other side of that split from expiry
- assert a wrong key and a tampered payload both reject with errors.JWSSignatureVerificationFailed and code ERR_JWS_SIGNATURE_VERIFICATION_FAILED, while decodeJwt still reports the forged claims
- assert issuer and audience are validated only when passed as options, failing with ERR_JWT_CLAIM_VALIDATION_FAILED and reason check_failed for a mismatch and reason missing for an absent claim
- assert a token minted with no exp verifies forever unless requiredClaims names exp
- assert alg is taken from the token header unless algorithms is pinned: a real HS512 token verifies unpinned but is refused with ERR_JOSE_ALG_NOT_ALLOWED when pinned
- assert an UnsecuredJWT alg:none token is refused by jwtVerify even unpinned, with ERR_JOSE_NOT_SUPPORTED, and that an RS256 header with a symmetric key is refused by the alg check when pinned and by a TypeError when not
- assert jose does not enforce the RFC 7518 minimum HMAC key size: a five-byte HS256 key signs and verifies, and WebCrypto underneath imports the same 40-bit HMAC key without complaint
- assert jwtVerify never throws synchronously, so an unawaited call yields a truthy Promise and its failure reaches process.unhandledRejection, and measure in a child process that the same orphaned rejection exits node with status 1
- assert jose ships no CJS export condition and no default export, that importing a default binding from it fails at link time with a SyntaxError, and measure that require('jose') nonetheless succeeds on Node 22
파일
- csx.json
- package-lock.json
- package.json
- src/index.mjs
- test/contract.mjs