| 1 |
--- |
| 2 |
title: Configure security |
| 3 |
linkTitle: Security |
| 4 |
description: Configure security. |
| 5 |
categories: [] |
| 6 |
keywords: [] |
| 7 |
--- |
| 8 |
|
| 9 |
Hugo's built-in security policy, which restricts access to `os/exec`, remote communication, and similar operations, is configured via allowlists. By default, access is restricted. If a build attempts to use a feature not included in the allowlist, it will fail, providing a detailed message. |
| 10 |
|
| 11 |
This is the default security configuration: |
| 12 |
|
| 13 |
{{< code-toggle config=security />}} |
| 14 |
|
| 15 |
`allowContent` |
| 16 |
: {{< new-in 0.162.0 />}} |
| 17 |
: (`[]string`) A slice of [regular expressions](g) matching the [media type](g) of [content formats](g) allowed in the `content` directory. By default, the HTML content format (media type `text/html`) is denied. Hugo emits HTML file content verbatim, which could allow arbitrary JavaScript execution. See the [classification][] table for a mapping of content formats to media types. |
| 18 |
|
| 19 |
`enableInlineShortcodes` |
| 20 |
: (`bool`) Whether to enable [inline shortcodes][]. Default is `false`. |
| 21 |
|
| 22 |
`exec.allow` |
| 23 |
: (`[]string`) A slice of [regular expressions](g) matching the names of external executables that Hugo is allowed to run. |
| 24 |
|
| 25 |
`exec.osEnv` |
| 26 |
: (`[]string`) A slice of [regular expressions](g) matching the names of operating system environment variables that Hugo is allowed to access. |
| 27 |
|
| 28 |
`funcs.getenv` |
| 29 |
: (`[]string`) A slice of [regular expressions](g) matching the names of operating system environment variables that Hugo is allowed to access with the [`os.Getenv`][] function. |
| 30 |
|
| 31 |
`http.methods` |
| 32 |
: (`[]string`) A slice of [regular expressions](g) matching the HTTP methods that the [`resources.GetRemote`][] function is allowed to use. |
| 33 |
|
| 34 |
`http.mediaTypes` |
| 35 |
: (`[]string`) Applicable to the `resources.GetRemote` function, a slice of [regular expressions](g) matching the `Content-Type` in HTTP responses that Hugo trusts, bypassing file content analysis for media type detection. |
| 36 |
|
| 37 |
`http.urls` |
| 38 |
: (`[]string`) A slice of [regular expressions](g) matching the URLs that the `resources.GetRemote` function is allowed to access. |
| 39 |
|
| 40 |
`node.permissions.disable` |
| 41 |
: {{< new-in 0.161.0 />}} |
| 42 |
: (`bool`) Whether to disable the Node.js [permission model][]. When `false`, Hugo runs Node.js tools with the `--permission` flag, restricting their file system and resource access to what is explicitly allowed below. Default is `false`. |
| 43 |
|
| 44 |
`node.permissions.allowAddons` |
| 45 |
: {{< new-in 0.161.0 />}} |
| 46 |
: (`[]string`) A slice of Node.js tool names permitted to load native addons (`--allow-addons`). |
| 47 |
|
| 48 |
`node.permissions.allowChildProcess` |
| 49 |
: {{< new-in 0.161.0 />}} |
| 50 |
: (`[]string`) A slice of Node.js tool names permitted to spawn child processes (`--allow-child-process`). |
| 51 |
|
| 52 |
`node.permissions.allowRead` |
| 53 |
: {{< new-in 0.161.0 />}} |
| 54 |
: (`[]string`) A slice of file system paths that Node.js tools are allowed to read (`--allow-fs-read`). Paths are relative to the working directory; `"."` means the working directory itself. Use `"*"` to allow all paths. |
| 55 |
|
| 56 |
`node.permissions.allowWorker` |
| 57 |
: {{< new-in 0.161.0 />}} |
| 58 |
: (`[]string`) A slice of Node.js tool names permitted to spawn worker threads (`--allow-worker`). |
| 59 |
|
| 60 |
`node.permissions.allowWrite` |
| 61 |
: {{< new-in 0.161.0 />}} |
| 62 |
: (`[]string`) A slice of file system paths that Node.js tools are allowed to write (`--allow-fs-write`). Paths are relative to the working directory; `"."` means the working directory itself. Use `"*"` to allow all paths. |
| 63 |
|
| 64 |
## Negation rules |
| 65 |
|
| 66 |
{{< new-in 0.161.0 />}} |
| 67 |
|
| 68 |
Any pattern in an allowlist can be negated by prefixing it with an exclamation mark (`!`) and one space to turn it into a deny rule. Deny rules take precedence over allow rules. An allowlist composed entirely of deny rules implicitly allows everything it does not deny. An empty allowlist rejects everything. |
| 69 |
|
| 70 |
For example, to allow all URLs except those pointing to `evil.example.com`: |
| 71 |
|
| 72 |
```toml |
| 73 |
[security.http] |
| 74 |
urls = ['.*', '! ^https?://evil\.example\.com'] |
| 75 |
``` |
| 76 |
|
| 77 |
Setting an allowlist to the string `none` will completely disable the associated feature. |
| 78 |
|
| 79 |
## Environment variables |
| 80 |
|
| 81 |
You can also override your project configuration with environment variables. For example, to block `resources.GetRemote` from accessing any URL: |
| 82 |
|
| 83 |
```txt |
| 84 |
export HUGO_SECURITY_HTTP_URLS=none |
| 85 |
``` |
| 86 |
|
| 87 |
Learn more about [using environment variables][] to configure your site. |
| 88 |
|
| 89 |
[`os.Getenv`]: /functions/os/getenv/ |
| 90 |
[`resources.GetRemote`]: /functions/resources/getremote/ |
| 91 |
[classification]: /content-management/formats/#classification |
| 92 |
[inline shortcodes]: /content-management/shortcodes/#inline |
| 93 |
[permission model]: https://nodejs.org/api/permissions.html#permission-model |
| 94 |
[using environment variables]: /configuration/introduction/#environment-variables |