> For the complete documentation index, see [llms.txt](https://coldbox-security.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox-security.ortusbooks.com/get-started/configuration.md).

# 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](/get-started/configuration/full-configuration.md) reference.

```javascript
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         | [Authentication](/get-started/configuration/authentication.md)                       |
| `firewall`                 | The validator, invalid actions, rules and logs | [Firewall](/get-started/configuration/firewall.md)                                   |
| `jwt`                      | JSON Web Token creation, storage and refresh   | [JWT](/get-started/configuration/jwt.md)                                             |
| `csrf`                     | The `cbcsrf` module                            | [Cross Site Request Forgery](/csrf-and-headers/cross-site-request-forgery-cbcsrf.md) |
| `basicAuth`                | Basic Auth hashing and in-config users         | [Basic Auth](/get-started/configuration/basic-auth.md)                               |
| `securityHeaders`          | Host, IP, SSL, HSTS and other protections      | [Security Headers](/csrf-and-headers/security-headers.md)                            |
| `visualizer`               | The rule debugging panel                       | [Visualizer](/get-started/configuration/visualizer.md)                               |
| `middleware`, `signedUrls` | Route middleware defaults and signed URLs      | [Route Middleware](/get-started/configuration/middleware.md)                         |
| everything                 | All settings and defaults in one block         | [Full Configuration](/get-started/configuration/full-configuration.md)               |

## 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:

```javascript
component {

    function configure(){
        return {
            authentication : { provider : "authenticationService@cbauth" },
            firewall       : {
                validator                  : "AuthValidator@cbsecurity",
                invalidAuthenticationEvent : "security.login"
            }
        };
    }

}
```

## 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`

{% code title="module/ModuleConfig.cfc" %}

```javascript
settings = {
    cbsecurity : {
        firewall : {
            // Where to go when a user is not logged in, and how: redirect, override or block
            invalidAuthenticationEvent  : "api:Home.onInvalidAuth",
            defaultAuthenticationAction : "override",
            // Where to go when a user lacks permissions, and how
            invalidAuthorizationEvent   : "api:Home.onInvalidAuthorization",
            defaultAuthorizationAction  : "override",
            // The validator for this module
            validator                   : "JwtAuthValidator@cbsecurity",
            // Rules as a simple array. You can also use the full form with
            // `inline`, `defaults` and `provider`, see the Firewall page.
            rules                       : [ { secureList : "api:Secure\.*" } ]
        }
    }
}
```

{% endcode %}

{% hint style="danger" %}
Please note that a module's security rules will be **PREPENDED** to the global rules
{% endhint %}

### 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://coldbox-security.ortusbooks.com/get-started/configuration.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
