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

Configuration

How to configure cbsecurity. Every setting has a default, so only set what you change.

Where to Configure

cbsecurity registers itself from the cbsecurity key of your moduleSettings in config/ColdBox.cfc. In ColdBox 7 and later you can instead create config/modules/cbsecurity.cfc (see below). You only need to set the keys you change, the rest keep their defaults.

Settings at a Glance

This is every top-level key with the values most apps set. Each section links to its page for the full list of options. If you want every setting with its default and a comment, see the Full Configuration reference.

moduleSettings = {
    // The user service cbauth uses to validate credentials
    cbauth : { userServiceClass : "models.UserService" },

    cbsecurity : {
        authentication : {
            provider        : "authenticationService@cbauth",
            userService     : "",
            prcUserVariable : "oCurrentUser"
        },
        firewall : {
            autoLoadFirewall            : true,
            validator                   : "AuthValidator@cbsecurity",
            handlerAnnotationSecurity   : true,
            invalidAuthenticationEvent  : "security.login",
            defaultAuthenticationAction : "redirect",
            invalidAuthorizationEvent   : "security.notAuthorized",
            defaultAuthorizationAction  : "redirect",
            rules                       : [ { secureList : "^admin", roles : "admin" } ],
            logs                        : { enabled : false }
        },
        jwt             : { secretKey : getSystemSetting( "JWT_SECRET", "" ) },
        csrf            : { enableAutoVerifier : false },
        basicAuth       : { users : {} },
        securityHeaders : { enabled : true },
        visualizer      : { enabled : false },
        middleware      : { trustedProxies : [] },
        signedUrls      : { secret : getSystemSetting( "CBSECURITY_SIGNING_SECRET", "" ) }
    }
}

Settings Pages

Key
What it configures
Page

authentication

The service that logs users in and out

firewall

The validator, invalid actions, rules and logs

jwt

JSON Web Token creation, storage and refresh

csrf

The cbcsrf module

basicAuth

Basic Auth hashing and in-config users

securityHeaders

Host, IP, SSL, HSTS and other protections

visualizer

The rule debugging panel

middleware, signedUrls

Route middleware defaults and signed URLs

everything

All settings and defaults in one block

ColdBox 7 Module Config File

In ColdBox 7 and later you can keep the settings in their own file, config/modules/cbsecurity.cfc, with a configure() method that returns the same structure:

Module Settings

Each module can also have its own CBSecurity settings which override or collaborate with the global settings. So what can a module do:

  • Have its own validator

  • Have its own security rules

  • Have its own invalid authentication event and action

  • Have its own invalid authorization event and action

You will create a cbsecurity struct within the module's settings struct in the ModuleConfig.cfc

Loading and Unloading

Also note that if modules are loaded dynamically, it will still inspect them and register them if cbsecurity settings are found. The same goes for unloading, the entire security rules for that module will cease to exist.

Last updated

Was this helpful?