hapi 20
Last reviewed Oct 25, 2026
Prompt Details
Prompt Composition
3prompts
- JavaScript ES2026102 lines · 3.1K tokens
- Node.js 24101 lines · 5.3K tokens
- 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 withoptions.auth: false,mode: 'optional', ormode: 'try'. Thetrymode 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 buildrequest.auth.credentialsfrom validated claims.Jwt.token.decode()is parsing, not authentication. - Set
options.auth.access.scopeandentityfor protected operations. Anaccessarray grants access when any entry matches; use+scopefor a required scope and!scopefor an excluded scope. Authorize the actual object and tenant after canonical lookup, not only a route parameter or a dynamic scope such asuser-{params.id}. - Keep a prerequisite that checks authorization before the write or external action it protects. Nested arrays in
options.prerun concurrently and sibling work continues after one fails; never put the check and protected action in the same parallel array. Keep authorization prerequisitefailAction: 'error'.