UNPKG

@adonisjs/shield

Version:

A middleware for AdonisJS to keep web applications secure from common web attacks

44 lines (43 loc) 1.55 kB
import type { Edge } from 'edge.js'; import type { HttpContext } from '@adonisjs/core/http'; import type { Encryption } from '@adonisjs/core/encryption'; import { noop } from '../noop.ts'; import type { CsrfOptions } from '../types.ts'; /** * A class to encapsulate the logic of verifying and generating * CSRF tokens. */ export declare class CsrfGuard { #private; /** * Creates a new CsrfGuard instance. * * @param options - CSRF configuration options * @param encryption - Encryption service instance * @param edge - Optional Edge template engine instance */ constructor(options: CsrfOptions, encryption: Encryption, edge?: Edge); /** * Handles CSRF verification for the current request. * Gets or creates a CSRF secret, generates a token, optionally sets XSRF cookie, * shares helpers with views, and validates the request if required. * * @param ctx - HTTP context object */ handle(ctx: HttpContext): Promise<void>; } /** * A factory function that returns a new function to enforce CSRF protection. * Creates a CsrfGuard instance and returns its handle method. * * @param options - CSRF configuration options * @param encryption - Encryption service instance * @param edge - Optional Edge template engine instance * * @example * const csrfGuard = csrfFactory({ * enabled: true, * methods: ['POST', 'PUT', 'DELETE'] * }, encryption, edge) */ export declare function csrfFactory(options: CsrfOptions, encryption: Encryption, edge?: Edge): typeof noop;