hapi 20

Last reviewed Oct 25, 2026

Export as PDF

Prompt Details

Prompt Composition

3prompts
  1. JavaScript ES2026102 lines · 3.1K tokens
  2. Node.js 24101 lines · 5.3K tokens
  3. hapi 2054 lines · 2.9K tokens
Total257 lines · 11.3K tokens

CWE Coverage

  • 20
  • 22
  • 59
  • 78
  • 79
  • 88
  • 89
  • 95
  • 113
  • 117
  • 201
  • 208
  • 209
  • 214
  • 250
  • 287
  • 295
  • 297
  • 306
  • 307
  • 319
  • 323
  • 330
  • 338
  • 346
  • 347
  • 352
  • 354
  • 362
  • 367
  • 377
  • 384
  • 426
  • 434
  • 444
  • 459
  • 471
  • 488
  • 494
  • 502
  • 524
  • 532
  • 552
  • 602
  • 613
  • 614
  • 639
  • 653
  • 674
  • 732
  • 770
  • 807
  • 829
  • 838
  • 862
  • 863
  • 908
  • 916
  • 918
  • 922
  • 942
  • 943
  • 1004
  • 1321
  • 1333

Prompt Preview

Apply these rules to hapi 20 applications alongside the included Node.js prompt. Put application policy on the routes and lifecycle points that actually handle the request; review plugin configuration separately when a companion module supplies the control.

Authentication and authorization

  • Register authentication schemes and strategies before routes, set server.auth.default() for protected route groups, and audit every route with options.auth: false, mode: 'optional', or mode: 'try'. The try mode lets invalid credentials reach the handler; make the handler's anonymous policy explicit.
  • Verify bearer tokens before using their claims. If using @hapi/jwt, keep verification enabled, constrain acceptable algorithms and signing keys, require the expected issuer and audience, enforce expiry and not-before checks, and build request.auth.credentials from validated claims. Jwt.token.decode() is parsing, not authentication.
  • Set options.auth.access.scope and entity for protected operations. An access array grants access when any entry matches; use +scope for a required scope and !scope for an excluded scope. Authorize the actual object and tenant after canonical lookup, not only a route parameter or a dynamic scope such as user-{params.id}.
  • Keep a prerequisite that checks authorization before the write or external action it protects. Nested arrays in options.pre run concurrently and sibling work continues after one fails; never put the check and protected action in the same parallel array. Keep authorization prerequisite failAction: 'error'.