Introducing a new way to review your PRs.

Read the announcement

bunkerity / bunkerweb

🛡️ Open-source and cloud-native Web Application Firewall (WAF)

View on GitHub

19 documents · Updated Nov 23, 2026

docs / extension-ecosystem

Extension ecosystem

BunkerWeb uses plugins as its extension model. A plugin adds focused security or service behavior while using BunkerWeb's shared request phases, configuration rules, data stores, jobs, and operator interfaces. This keeps new behavior in the shared runtime and makes its settings part of the normal configuration contract. See Plugin system for the detailed plugin guide.

Extension model

The extension model treats core, external, and Pro plugins as peers after they pass the same metadata checks. Each plugin declares its identity, supported stream mode, settings, and optional scheduled work. Its code then joins the shared BunkerWeb lifecycle. The main difference is where the plugin comes from, not how the runtime uses its contract.

Plugin groupPurposeHow it enters the runtime
CoreBuilt-in BunkerWeb behaviorLoaded from the core plugin set
ExternalUser or community behaviorLoaded from the external plugin set
ProLicensed behaviorLoaded from the Pro plugin set

The metadata file is the contract between an extension and the platform. BunkerWeb checks required identity, version, stream, and setting data before a plugin can affect generated configuration. It also checks setting names, scopes, types, value rules, and job declarations. References: src/…/Configurator.py• L24-49, src/…/Configurator.py• L198-247, src/…/Configurator.py• L442-536

Shared configuration contract

Plugin settings become normal BunkerWeb settings. The configuration system combines global settings with plugin settings, applies defaults, accepts configured overrides, checks each value against the declared rule, and expands multisite settings for each service. This gives the scheduler, configuration renderer, request runtime, and UI one source of truth.

Settings have one of two scopes: global applies to BunkerWeb as a whole, while multisite can vary by protected service. A plugin must declare the scope that matches its behavior. Invalid values or unknown setting names do not silently become runtime state.

The configuration renderer makes plugin configuration active in two ways. Plugin templates join the shared template search path, and the resulting values are written into the generated runtime configuration. A plugin can therefore add NGINX behavior without creating a separate configuration pipeline.

For example, the Zstandard plugin declares service-level controls for enabling compression, selecting MIME types, setting a minimum response size, and choosing a compression level. The platform presents these as validated settings with defaults rather than as a separate configuration system. References: src/…/Configurator.py• L249-366, src/…/Configurator.py• L379-434, src/…/Templator.py• L312-365, src/…/Templator.py• L554-571, src/…/plugin.json• L2-64

Runtime lifecycle

The runtime loads each valid plugin's metadata and optional Lua module. It records the lifecycle phases that the module supports. At request time, BunkerWeb creates the plugin with shared request context and shared stores before it calls the method for the current phase. The plugin returns a common result shape so the runtime can decide whether to continue, deny, redirect, or report an error.

The lifecycle covers startup, worker setup, request handling, response handling, stream handling, logging, timers, and certificate work. BunkerWeb orders plugins separately for each phase. The default order is defined centrally, and operators can provide global or per-service order overrides when behavior depends on sequence.

The flow below shows how an extension moves from metadata to shared runtime behavior.

flowchart LR
    A[Plugin metadata] --> B[Validate settings and jobs]
    B --> C[Load plugin module]
    C --> D[Detect supported phases]
    D --> E[Order plugins per phase]
    E --> F[Create shared runtime context]
    F --> G[Call plugin phase]
    G --> H[Apply common result]

The default phase order coordinates built-in behavior such as access checks, response headers, stream inspection, logging, and timers. It also leaves some phases empty by default, which allows a plugin to participate only when it declares support for that phase. References: src/…/order.json• L1-65, src/bw/lua/bunkerweb/helpers.lua#L26-L77, src/bw/lua/bunkerweb/helpers.lua#L92-L231, src/bw/lua/bunkerweb/helpers.lua#L234-L285, src/bw/lua/bunkerweb/plugin.lua#L26-L102, src/bw/lua/bunkerweb/utils.lua#L1672-L1691

Shared runtime resources

Every plugin receives the same runtime services instead of owning a separate execution environment. These services give extensions a consistent way to read declared settings, log, keep local state, share state across BunkerWeb instances, cache results, and publish metrics.

The shared context also carries request facts that BunkerWeb has already normalized. Several plugins can therefore inspect the same client and service data without rebuilding that context.

Shared resourceRole
Plugin variablesValues declared by the plugin's settings
Request contextNormalized request, client, service, and protocol data
Internal storeShared runtime data for one BunkerWeb instance
Cluster storeData shared across BunkerWeb instances
Cache storesLocal or shared results for repeated checks
Logger and metricsOperational records and plugin-scoped measurements

References: src/…/plugin.lua• L47-102 src/…/helpers.lua• L288-348 src/…/plugin.lua• L113-184

Extension delivery

External plugins can arrive from a local plugin directory or from archive URLs configured through EXTERNAL_PLUGIN_URLS. The download job accepts ZIP and TAR archives, extracts them to a temporary area, checks that each discovered plugin has metadata, and installs the result into the external plugin area. It then records the plugin data and checksum so the scheduler and database can track the installed set.

Installation replaces a plugin as one file-system operation and removes invalid plugin directories. This protects the shared runtime from a partly updated extension. The same metadata is later loaded with core and Pro plugins, so delivery does not change the runtime contract.

References: src/…/download-plugins.py• L39-56 src/…/download-plugins.py• L77-151 src/…/download-plugins.py• L155-253 src/…/download-plugins.py• L260-315

Extension surfaces

A plugin can extend more than request checks. The ecosystem supports several surfaces that use the same metadata and shared configuration model.

  • Request and stream behavior: Lua lifecycle methods can inspect traffic, allow it, deny it, redirect it, or record a result.
  • Generated configuration: Configuration templates add behavior at supported NGINX, security, or stream contexts.
  • Scheduled work: Declared jobs run once or on a fixed time cycle. A job can request a configuration reload after it changes managed data.
  • Web UI: A plugin UI can expose pages and actions through the existing UI runtime.
  • CLI and API: A plugin can add bwcli commands and handle API calls through the shared plugin dispatch path.
  • Reusable templates: A plugin can provide templates that change default settings for a repeatable service setup.

These surfaces are optional. A small extension can use one surface, while a larger integration can combine configuration, request checks, scheduled sync, and operator controls without creating a new platform service.

References: src/…/Configurator.py• L43-49 src/…/plugin.json• L1-45 src/…/Templator.py• L554-600 src/…/api.lua• L1060-1117 docs/plugins.md• L266-302

Plugin system guide

The Plugin system page is the child page for plugin structure, metadata, settings, lifecycle hooks, jobs, UI pages, CLI commands, and installation details. Use this page first to understand the boundaries that every extension must preserve.

References: docs/plugins.md• L1-3 docs/plugins.md• L258-302

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep metadata validation, configuration loading, runtime phase discovery, and UI setting handling aligned when a new setting type or scope is added.
  • Keep plugin ordering names aligned between phase discovery, default order data, and global or per-service order overrides.
  • Keep archive installation, database plugin records, and runtime plugin directories consistent when changing external plugin updates.
  • Keep the common result fields aligned between plugin methods and the request or API dispatchers that consume them.
  • Keep a plugin's declared stream capability aligned with the phases and configuration contexts it actually uses.

Important failure modes

TriggerConsequenceGuard
Missing or invalid plugin.json fieldsThe plugin is ignored during configuration or runtime loading.Validate the metadata contract before installation and load.
Plugin module fails to load or lacks the required constructorThe plugin cannot join the lifecycle.Load the module and verify its constructor before phase use.
Setting scope or value rule does not match the configured formThe value is rejected or the service-specific behavior is absent.Declare the correct scope and validation rule in metadata.
Plugin order names a plugin that does not support that phaseThe requested order entry is reported as missing and is not applied.Use the plugin's discovered phase set when defining overrides.
External archive download or extraction failsThe update is skipped and the prior installed set remains available.Use supported archives and rely on temporary extraction plus atomic replacement.
Plugin phase returns no common resultRuntime dispatch treats the call as failed.Return the shared result fields required by the plugin base contract.

Key files

FileWhy to read it
src/…/Configurator.pyShows the shared metadata and setting contract for core, external, and Pro plugins.
src/…/Templator.pyShows how plugin configuration templates join the main configuration render.
src/…/order.jsonShows the default order for plugin lifecycle phases.
src/bw/lua/bunkerweb/helpers.luaShows plugin loading, phase discovery, ordering, construction, and result checks.
src/bw/lua/bunkerweb/plugin.luaShows the shared context, stores, variables, metrics, and logging base.
src/…/download-plugins.pyShows external archive delivery and safe installation.
src/…/plugin.jsonShows a plugin metadata contract with validated per-service settings.
src/bw/lua/bunkerweb/api.luaShows how plugin API handlers use the shared dispatch contract.
docs/plugins.mdChild-level guide for creating, installing, and operating a plugin.