
Security News
Security Community Slams MIT-linked Report Claiming AI Powers 80% of Ransomware
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.
hapi-auth-cookie-basic
Advanced tools
hapi Cookie authentication plugin
ScreenShot :

Written hapi-auth-basic on hapi-auth-cookie
Lead Maintainer: James Weston
Cookie authentication provides simple cookie-based session management. The user has to be authenticated via other means, typically a web form, and upon successful authentication the browser receives a reply with a session cookie. The cookie uses Iron to encrypt and sign the session content.
Subsequent requests containing the session cookie are authenticated and validated via the provided validateFunc in case the cookie's encrypted content requires validation on each request.
It is important to remember a couple of things:
The 'cookie' scheme takes the following options:
cookie - the cookie name. Defaults to 'sid'.password - used for Iron cookie encoding. Should be at least 32 characters long.ttl - sets the cookie expires time in milliseconds. Defaults to single browser session (ends
when browser closes). Required when keepAlive is true.domain - sets the cookie Domain value. Defaults to none.path - sets the cookie path value. Defaults to /.clearInvalid - if true, any authentication cookie that fails validation will be marked as
expired in the response and cleared. Defaults to false.keepAlive - if true, automatically sets the session cookie after validation to extend the
current session for a new ttl duration. Defaults to false.isSameSite - if false omitted. Other options Strict or Lax. Defaults to Strict.isSecure - if false, the cookie is allowed to be transmitted over insecure connections which
exposes it to attacks. Defaults to true.isHttpOnly - if false, the cookie will not include the 'HttpOnly' flag. Defaults to true.validateFunc - an optional session validation function used to validate the content of the
session cookie on each request. Used to verify that the internal session state is still valid
(e.g. user account still exists). The function has the signature function(request, session, callback)
where:
request - is the Hapi request object of the request which is being authenticated.session - is the session object set via request.cookieAuth.set().callback - a callback function with the signature function(err, isValid, credentials)
where:
err - an internal error.isValid - true if the content of the session is valid, otherwise false.credentials - a credentials object passed back to the application in
request.auth.credentials. If value is null or undefined, defaults to session. If
set, will override the current cookie as if request.cookieAuth.set() was called.requestDecoratorName - USE WITH CAUTION an optional name to use with decorating the request object.  Defaults to 'cookieAuth'.  Using multiple decorator names for separate authentication strategies could allow a developer to call the methods for the wrong strategy.  Potentially resulting in unintended authorized access.When the cookie scheme is enabled on a route, the request.cookieAuth objects is decorated with
the following methods:
set(session) - sets the current session. Must be called after a successful login to begin the
session. session must be a non-null object, which is set on successful subsequent
authentications in request.auth.credentials where:
session - the session object.set(key, value) - sets a specific object key on the current session (which must already exist)
where:
key - session key string.value - value to assign key.clear([key]) - clears the current session or session key where:
key - optional key string to remove a specific property of the session. If none provided,
defaults to removing the entire session which is used to log the user out.ttl(msecs) - sets the ttl of the current active session where:
msecs - the new ttl in milliseconds.Because this scheme decorates the request object with session-specific methods, it cannot be
registered more than once.
FAQs
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.

Research
/Security News
Socket researchers found 10 typosquatted npm packages that auto-run on install, show fake CAPTCHAs, fingerprint by IP, and deploy a credential stealer.