Authentication and safety
Keep queue data private and grant operational controls deliberately.
Application-owned authentication#
Queuebert does not authenticate requests for you. The Nest module can apply your guards and controller class decorators to all generated endpoints. Protect reads as well as writes: queue names, failure information, cache metadata, and Redis statistics may be sensitive.
Use your existing admin authorization system where possible. Keep write-capable credentials separate from read-only access, audit operator actions in your application, and expose only the endpoints each deployment needs.
Bearer-token example#
For a simple server-to-client integration, this guard accepts a shared token from Authorization: Bearer <token>. Store a strong token in a server-side secret, rotate it through your deployment process, and only send it over HTTPS outside local development. This example does not provide user-level roles, expiration, or revocation; use your normal identity system when you need those.
// admin.guard.ts
import { CanActivate, ExecutionContext, Injectable, UnauthorizedException } from '@nestjs/common';
import { timingSafeEqual } from 'node:crypto';
@Injectable()
export class AdminGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean {
const expected = process.env.QUEUEBERT_TOKEN;
const request = context.switchToHttp().getRequest<{
headers: { authorization?: string };
}>();
const authorization = request.headers.authorization;
const provided = authorization?.startsWith('Bearer ') ? authorization.slice(7) : '';
if (!expected || !provided) throw new UnauthorizedException();
const actualBytes = Buffer.from(provided);
const expectedBytes = Buffer.from(expected);
if (actualBytes.length !== expectedBytes.length || !timingSafeEqual(actualBytes, expectedBytes)) {
throw new UnauthorizedException();
}
return true;
}
}Attach it using auth: { guards: [AdminGuard] } as shown in getting started. The guard fails closed if the server token is missing. Queuebert itself does not prescribe a token format; your guard decides how credentials are validated.
Never put a server secret in a NEXT_PUBLIC_* variable or bundle it into a public web app. A browser user can inspect any credential available to that browser. Prefer an authenticated application backend for browser access to privileged operations.
Endpoint permissions#
stats is always enabled. The default optional capability is only metrics. Explicitly opt in to mutations, for example with endpoints: ['metrics', 'pause', 'resume'] in your module options.
Enabling an endpoint is not authorization. Guards/decorators and your network policy must still decide who may call it. Do not enable clean, drain, or migrations unless operators genuinely need them; those operations can remove or move queue data.
Deployment checklist#
- Keep Redis connection details on your server and restrict Redis network access.
- Use HTTPS, a trusted network, or an authenticated reverse proxy for the API.
- Verify unauthenticated requests are rejected, including
GET /stats. - Allow only necessary origins and headers in CORS for browser clients. CORS is not authentication.
- If using cookie authentication, apply your application's CSRF protection to mutations.
- Keep
includeJobDataInMigrationPreviewdisabled unless an authorized client must see raw payloads. Review all other returned metadata for secrets too. - Use
includeRedisStats: falseif clients should not see Redis infrastructure statistics. - Test write operations against disposable queues before enabling them in production.