Skip to content

otplib API Documentation / @otplib/core / utils / hasGuardrailOverrides

Function: hasGuardrailOverrides() ​

hasGuardrailOverrides(guardrails): boolean

Defined in: packages/core/src/utils.ts:305

Check if guardrails contain custom overrides

Returns true if the guardrails object was created with custom values, false if using RFC-recommended defaults. Useful for security auditing, compliance monitoring, and development warnings.

This function accesses a module-private Symbol property that cannot be accessed or modified outside this module, ensuring reliable detection.

Parameters ​

guardrails ​

OTPGuardrails

The guardrails object to check

Returns ​

boolean

true if guardrails were customized, false if using defaults

Examples ​

Security monitoring

ts
import { createGuardrails, hasGuardrailOverrides } from '@otplib/core';

const guardrails = createGuardrails({ MAX_WINDOW: 20 });

if (hasGuardrailOverrides(guardrails)) {
  console.warn('Custom guardrails detected:', guardrails);
  // Log to security audit system
}

Compliance check

ts
function validateGuardrails(guardrails: OTPGuardrails) {
  if (hasGuardrailOverrides(guardrails)) {
    throw new Error('Custom guardrails not allowed in production');
  }
}

Released under the MIT License.