RRESAFE
Resafe / api

API Reference

Complete API documentation for Resafe.

check(regex, options)

The primary function that analyzes regex patterns for ReDoS vulnerabilities.

import { check } from "resafe";

const result = check(pattern, options);

Parameters

regex

  • Type: string | RegExp
  • Required: Yes
  • Description: The regex pattern to analyze
// String pattern
check("(a+)+$");

// RegExp object
check(/(a+)+$/);

options

  • Type: Options
  • Required: No
  • Description: Configuration options

Options

PropertyTypeDefaultDescription
thresholdnumber1.0Spectral radius threshold for unsafe patterns
silentbooleanfalseDisable console logging
throwErrbooleanfalseThrow error for unsafe patterns

Return Value

Returns a Result object:

interface Result {
  safe: boolean;     // Whether the pattern is safe
  radius: number;    // Spectral radius value
}

checkAsync(regex, options)

Asynchronous version of check() that returns a Promise. Useful for integration with async workflows.

import { checkAsync } from "resafe";

const result = await checkAsync(pattern, options);

Parameters

Same as check():

  • regex: string | RegExp - The regex pattern to analyze
  • options: Options - Configuration options (optional)

Return Value

Returns a Promise<Result>:

interface Result {
  safe: boolean;
  radius: number;
}

On this page