Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Security

Secure ColdBox applications with cbsecurity, the recommended engine for authentication, authorization, JWT, CSRF and security headers.

cbsecurity is the recommended way to secure a ColdBox application. Instead of hand-rolling login checks in handlers and interceptors, you declare who can reach what and cbsecurity enforces it before your handlers run, over sessions or JWT.

box install cbsecurity

📖 Full documentation: coldbox-security.ortusbooks.com

Your First Secured Application

Configure the module in your ColdBox class. Authentication is delegated to cbauth, which needs a user service of your own.

// config/ColdBox.bx
moduleSettings = {
    cbauth : { userServiceClass : "UserService" },
    cbsecurity : {
        firewall : {
            // Where to send guests and users without access
            invalidAuthenticationEvent : "main.login",
            invalidAuthorizationEvent  : "main.unauthorized",
            rules : [
                { secureList : "^admin", roles : "admin" }
            ]
        }
    }
}
// config/ColdBox.cfc
moduleSettings = {
    cbauth : { userServiceClass : "UserService" },
    cbsecurity : {
        firewall : {
            // Where to send guests and users without access
            invalidAuthenticationEvent : "main.login",
            invalidAuthorizationEvent  : "main.unauthorized",
            rules : [
                { secureList : "^admin", roles : "admin" }
            ]
        }
    }
};

Three Ways to Declare Security

All three share the same validators, invalid actions, interception points and logging, so pick the one that matches where you want the rule to live.

Approach
Declared in
Best for

Firewall rules

Config, JSON, XML, a database or a model

Central, data-driven policies.

Annotations

On the handler or action

Security that travels with the code.

Route middleware

Next to the route in config/Router

Securing routes and groups with no rules file.

Route middleware needs ColdBox 8.2+ and cbsecurity 3.9+. See Route Middleware and the cbsecurity Route Middleware guide.

How a Request Is Secured

A denied request never reaches the handler. The firewall's settings decide whether the user is redirected, sent to an override event, or blocked with a 401.

What You Get

Capability
Provided by

Firewall, annotations and route middleware

cbsecurity

Authentication: authenticate(), isLoggedIn(), getUser()

cbauth

JWT access and refresh tokens

cbsecurity

CSRF tokens for forms and AJAX

cbcsrf

HTTP security response headers

cbsecurity

Firewall visualizer

cbsecurity

See Also

Last updated

Was this helpful?