--- layout: doc title: Security - Which files and hosts Kubb may read description: Reference for the security option in kubb.config.ts. The read and net rules, the files Kubb always refuses, the trusted input, the proxy, and what a Kubb Studio agent and the MCP server allow. outline: - 2 - 3 order: 3 navigation: title: Security icon: i-iconoir-shield-check --- # Security A spec can point at other files and URLs with `$ref`. The [`security`](/docs/5.x/reference/configuration#security) option in `kubb.config.ts` sets which local files and hosts Kubb reads for them. A file or host the rules refuse fails the run with [`KUBB_ACCESS_REFUSED`](/docs/5.x/reference/diagnostics#kubb-access-refused). ```ts [kubb.config.ts] import { defineConfig } from 'kubb/config' export default defineConfig({ security: { read: { allow: ['../shared-schemas'], deny: ['fixtures/private/**'] }, net: { allow: ['specs.corp.internal'], deny: ['*.example.org'] }, }, }) ``` The same rules apply wherever Kubb runs: on your machine, on a CI runner, in the MCP server, and on a Kubb Studio agent. Without `security`, `kubb generate`, `kubb validate`, and `unplugin-kubb` read every file and host. The MCP server and a Kubb Studio agent always apply the [built-in rules](#built-in). [Limit what a spec may read](/docs/5.x/how-to/recipes#security) has a config for each common case. What Kubb Studio may do on your machine, such as writing files, is a separate topic: see [Permissions](/docs/5.x/reference/permissions). ## The built-in rules {#built-in} Once `security` is set, Kubb starts from these rules and adds yours: | Part | Built-in rule | | --- | --- | | Files | Inside the project `root`, and in the folder of a file `input` | | Secret files | [Always refused](#secret-files) | | File endings | `.json`, `.yaml`, `.yml`, `.md` | | Hosts | Public hosts only | ## `read` {#read} Which local files a `$ref` may read. `false` reads none, and `true` reads any folder and skips the file ending check. | Setting | Default | What it does | | --- | --- | --- | | `read.allow` | `['.']` | Folders or globs a `$ref` file must be inside, relative to `root`. Yours add to the project folder | | `read.deny` | [Secret files](#secret-files) | Globs that are refused inside `allow` too. Yours add to the secret list | | `read.extensions` | `.json`, `.yaml`, `.yml`, `.md` | Endings a `$ref` file must have. Yours add to the list | A glob takes `*`, `**`, `?`, and one `{a,b}` group. It has no `[abc]` class and no `!` negation, and it matches upper and lower case as written. A pattern without a slash matches the file name in any folder. ## `net` {#net} Which hosts Kubb may request. `false` reaches none, and `true` reaches any host. | Setting | Default | What it does | | --- | --- | --- | | `net.public` | `true` | Allows every host whose addresses are all public. Set `false` to reach only the hosts in `allow` | | `net.allow` | `[]` | Hosts that are always allowed, private ones too: `host`, `*.host`, `host:port`, or an IP address | | `net.deny` | `[]` | Hosts that are always refused. A deny wins over an allow | | `net.proxy` | `false` | Sends requests through HTTP_PROXY or HTTPS_PROXY. See [Proxy](#proxy) | | `net.transport` | `nodeTransport` | The code that opens the connection | A host is not public when it is `localhost`, a private network address, or a cloud metadata address. A redirect to such a host is refused too. ## Secret files {#secret-files} Kubb refuses these files always, and `read: true` does not change that: - `.env` and `.env.*` - Key and certificate files: `*.crt`, `*.pem`, `*.key`, `*.p12`, `*.pfx`, `*.cer`, `*.der` - `.npmrc`, `.netrc`, `auth.json`, `token.json`, `kubeconfig*` - `credentials*.json`, `credentials*.yaml`, `credentials*.yml`, `service-account*.json` - `secret.*` and `secrets.*` - `*.tfstate`, `*.tfvars`, and `*.tfvars.json` - Anything under `.git`, `.ssh`, `.aws`, `.kube`, `.gnupg`, `.docker`, or `.kubb` ## The input {#input} The `input` your config names is always read. - The folder of a file input is readable. - Every URL on the origin of a URL input is allowed. - The host of a git input is allowed. A git repository on a host the `net` rules refuse is not fetched. ## Different rules per environment {#environments} The config is TypeScript, so read the environment when one place needs another rule: ```ts [kubb.config.ts] import { defineConfig } from 'kubb/config' export default defineConfig({ security: { // No network on a CI runner. net: process.env.CI ? false : { allow: ['specs.corp.internal'] }, }, }) ``` ## Proxy {#proxy} With `net.proxy: true`, requests go through HTTP_PROXY or HTTPS_PROXY. Kubb then checks the hostname only, because the proxy makes the connection. A host on NO_PROXY gets a direct connection, with the address check. An entry is `host`, `.host`, `host:port`, or `*`. An address range such as `10.0.0.0/8` is not matched. ## Kubb Studio and the MCP server {#studio-and-mcp} | Run | Files it reads | What your `security` can do | | --- | --- | --- | | A Kubb Studio agent you host | The built-in rules | Open and close | | The MCP server | The built-in rules | Open and close | | A hosted Kubb Studio agent | Only the repository of a git input | Only close | - "Only close" means a deny list, `false`, and `net.public: false` apply. An `allow` list and `true` do not.