Skip to content
Reference

Security

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.

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.

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.

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:

PartBuilt-in rule
FilesInside the project root, and in the folder of a file input
Secret filesAlways refused
File endings.json, .yaml, .yml, .md
HostsPublic hosts only

read

Which local files a $ref may read. false reads none, and true reads any folder and skips the file ending check.

SettingDefaultWhat it does
read.allow['.']Folders or globs a $ref file must be inside, relative to root. Yours add to the project folder
read.denySecret filesGlobs that are refused inside allow too. Yours add to the secret list
read.extensions.json, .yaml, .yml, .mdEndings 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.

SettingDefaultWhat it does
net.publictrueAllows 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.proxyfalseSends requests through HTTP_PROXY or HTTPS_PROXY. See Proxy
net.transportnodeTransportThe 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:

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

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

The config is TypeScript, so read the environment when one place needs another rule:

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

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

RunFiles it readsWhat your security can do
A Kubb Studio agent you hostThe built-in rulesOpen and close
The MCP serverThe built-in rulesOpen and close
A shared Kubb Studio agentNoneOnly close
A hosted Kubb Studio agentOnly the repository of a git inputOnly close
  • "Only close" means a deny list, false, and net.public: false apply. An allow list and true do not.