Debian Codegraph @

docs/content/en/configuration/security.md

raw
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.proxyFromEnvironment`
38 : {{< new-in 0.166.0 />}}
39 : (`bool`) Whether the `resources.GetRemote` function honors the `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` environment variables. Default is `false`. When a proxy is used, Hugo connects to the proxy rather than the destination, so the resolved address validation described under `http.urls` does not apply.
40
41 `http.urls`
42 : (`[]string`) A slice of [regular expressions](g) matching the URLs that the `resources.GetRemote` function is allowed to access.
43
44 The default allowlist denies URLs with an IP address or `localhost` as the host name. In addition, with the default allowlist, Hugo validates the resolved address when connecting and rejects connections to loopback, private, link-local, and other non-public addresses, e.g. a host name that resolves to a cloud metadata endpoint. This validation is disabled if you override `http.urls`, as the override may intentionally allow access to hosts on your local network, such as a development server.
45
46 `node.permissions.disable`
47 : {{< new-in 0.161.0 />}}
48 : (`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`.
49
50 `node.permissions.allowAddons`
51 : {{< new-in 0.161.0 />}}
52 : (`[]string`) A slice of Node.js tool names permitted to load native addons (`--allow-addons`).
53
54 `node.permissions.allowChildProcess`
55 : {{< new-in 0.161.0 />}}
56 : (`[]string`) A slice of Node.js tool names permitted to spawn child processes (`--allow-child-process`).
57
58 `node.permissions.allowRead`
59 : {{< new-in 0.161.0 />}}
60 : (`[]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.
61
62 Node.js follows symbolic links even when they point outside the allowed paths. Hugo therefore fails the build if any allowed path contains a symbolic link whose target resolves outside the allowed set. To permit such a link, add its target to the list. The check runs once per build; if you also grant write access to an allowed path, a Node.js tool can create links at build time that escape this check.
63
64 `node.permissions.allowWorker`
65 : {{< new-in 0.161.0 />}}
66 : (`[]string`) A slice of Node.js tool names permitted to spawn worker threads (`--allow-worker`).
67
68 `node.permissions.allowWrite`
69 : {{< new-in 0.161.0 />}}
70 : (`[]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.
71
72 ## Negation rules
73
74 {{< new-in 0.161.0 />}}
75
76 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.
77
78 For example, to allow all URLs except those pointing to `evil.example.com`:
79
80 ```toml
81 [security.http]
82 urls = ['.*', '! ^https?://evil\.example\.com']
83 ```
84
85 Setting an allowlist to the string `none` will completely disable the associated feature.
86
87 ## Environment variables
88
89 You can also override your project configuration with environment variables. For example, to block `resources.GetRemote` from accessing any URL:
90
91 ```txt
92 export HUGO_SECURITY_HTTP_URLS=none
93 ```
94
95 Learn more about [using environment variables][] to configure your site.
96
97 [`os.Getenv`]: /functions/os/getenv/
98 [`resources.GetRemote`]: /functions/resources/getremote/
99 [classification]: /content-management/formats/#classification
100 [inline shortcodes]: /content-management/shortcodes/#inline
101 [permission model]: https://nodejs.org/api/permissions.html#permission-model
102 [using environment variables]: /configuration/introduction/#environment-variables