This package provides a robust CSRF (Cross-Site Request Forgery) protection mechanism for NestJS applications, leveraging dynamic module registration for flexible configuration.
- Easy integration with NestJS projects.
- Customizable token generation and validation routes.
- Secure token handling using cookies.
npm install csrf-nest
- Module Import: Import
CsrfModule
into your application module:
import { CsrfModule } from 'csrf-nest';
@Module({
imports: [
CsrfModule.forRoot({
tokenGenerationUrl: '/api/csrf-token', // optional custom path
}),
],
})
export class AppModule {}
- Service Injection (optional): If you need direct access to CSRF functionality:
import { CsrfService } from 'csrf-nest';
@Injectable()
export class YourService {
constructor(private readonly csrfService: CsrfService) {}
}
TBH
TBH