Security
A spec can point at other files and URLs with $ref. The 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.
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.
Limit what a spec may read 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.
The built-in rules
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 |
| File endings | .json, .yaml, .yml, .md |
| Hosts | Public hosts only |
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 | 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
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 |
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
Kubb refuses these files always, and read: true does not change that:
.envand.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*.jsonsecret.*andsecrets.**.tfstate,*.tfvars, and*.tfvars.json- Anything under
.git,.ssh,.aws,.kube,.gnupg,.docker, or.kubb
The 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
netrules refuse is not fetched.
Different rules per environment
The config is TypeScript, so read the environment when one place needs another rule:
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
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
| 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 shared Kubb Studio agent | None | Only close |
| A hosted Kubb Studio agent | Only the repository of a git input | Only close |
- "Only close" means a deny list,
false, andnet.public: falseapply. Anallowlist andtruedo not.
