createWAF(config)
async
factory
Loads the Coraza WASM, compiles the provided SecLang directives, and returns a long-lived WAF instance. Call once at boot and reuse across requests.
signature
function createWAF(config: WAFConfig): Promise<WAF>
interface WAFConfig {
/** SecLang directives. Usually recommended() from @coraza/coreruleset. */
rules: string
/** 'detect' logs matches; 'block' denies on interruption. Default 'detect'. */
mode?: 'detect' | 'block'
/** Custom logger. Defaults to console. */
logger?: Logger
/** Override the embedded WASM binary (tests / custom builds only —
* the default loader is bundler-resilient and handles Next 15 / Turbopack
* rewriting `import.meta.url`. No override required in normal apps. */
wasmSource?: ArrayBufferLike | Uint8Array | URL | string
}
Example
import { createWAF } from '@coraza/core'
import { recommended } from '@coraza/coreruleset'
const waf = await createWAF({
rules: recommended({
paranoia: 1,
excludeCategories: ['scanner-detection', 'dos-protection'],
}),
mode: 'block',
})