carlos / platform Public

infra: pdf-host blocks loopback names in Chromium

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 7be85f133201baa0776418715d42f70b6915aef4 parent 9378258
6 files changed, +47 −20
  • docs/superpowers/notes/census-proposal-design-pdf-service.md +1 −1
  • infra/modules/pdf-host/README.md +12 −7
  • infra/modules/pdf-host/pdf-init.sh.tftpl +1 −1
  • infra/modules/pdf-host/tests/pdf_host.tftest.hcl +26 −4
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −1
  • internal/provision/testdata/plan14-root-reads-design-pdf-service.tsv +6 −6

CI passed — run details

diff --git a/docs/superpowers/notes/census-proposal-design-pdf-service.md b/docs/superpowers/notes/census-proposal-design-pdf-service.md
index c37922fc3..8569e730a 100644
--- a/docs/superpowers/notes/census-proposal-design-pdf-service.md
+++ b/docs/superpowers/notes/census-proposal-design-pdf-service.md
@@ -25,6 +25,6 @@ New dispositions, which census-propose wrote and the reviewer checks against the
- new `infra/modules/pdf-host/variables.tf:external`: reads +file:external; written legacy, accepted-legacy, frozen
- new `infra/modules/pdf-host/versions.tf:external`: reads +file:external; written legacy, accepted-legacy, frozen
-Seal: `3b6cd29b87d2728254936722ab45fdadcfbb8c1f5b74fdfa19d1921b9dfd1dbe` → `3c1c047d5919adccbab7d99a91056ace9a4d69a49ad9d6713aab6fd560b4ce25`.
+Seal: `3b6cd29b87d2728254936722ab45fdadcfbb8c1f5b74fdfa19d1921b9dfd1dbe` → `bcc149b3b39921018987ae5543414984d8fe10a9b2d12d94e2bed548f9d1c0a4`.
Overlay: `internal/provision/testdata/plan14-root-reads-design-pdf-service.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/infra/modules/pdf-host/README.md b/infra/modules/pdf-host/README.md
index 20e341ba3..a19a71803 100644
--- a/infra/modules/pdf-host/README.md
+++ b/infra/modules/pdf-host/README.md
@@ -86,9 +86,11 @@ image layers. The flag declarations at tag `v8.39.0` confirm `--api-timeout`,
`--api-download-from-deny-private-ips` and `--webhook-disable`. Chromium and
`downloadFrom` reject private IP destinations inside the engine as a second
layer. Webhooks are disabled, so the former webhook deny-list is redundant
-and removed. The Chromium pattern remains `^file:(?!//\/tmp/).*`, that
-version's default restriction on local file access; the IP flags do not
-replace it. These are source checks; the image was not run here.
+and removed. The Chromium pattern keeps Gotenberg 8.39.0’s default
+file rule `^file:(?!//\/tmp/).*` and also blocks loopback addresses and names.
+This stops a rendered page from calling the engine’s own API on port 3000.
+The private-IP flags are a separate layer and do not replace the pattern.
+These are source checks; the image was not run here.
All 15 routes in the console's allow-list were checked against that tag's
route definitions and registration: Chromium convert and screenshot for
@@ -127,10 +129,13 @@ the results for the deployment.
6. With the private-IP flags, capability drop and memory cap enabled, convert
uploaded HTML (its `file://` input under `/tmp`) and a LibreOffice document.
Both must succeed; a public image by hostname must still load.
-7. Render HTML referencing [http://127.0.0.1:3000/health](http://127.0.0.1:3000/health)
- and making a JavaScript `fetch` POST to `/forms/chromium/convert/html` on
- that origin. None may be fetched. Check the engine log: no second request
- may reach the engine.
+7. Render HTML that references
+ [http://127.0.0.1:3000/health](http://127.0.0.1:3000/health),
+ `http://x.localhost:3000/health`, `http://ip6-localhost:3000/health`,
+ `http://[::ffff:7f00:1]:3000/health`, and `http://0.0.0.0:3000/health`.
+ Also make a JavaScript `fetch` POST to `/forms/chromium/convert/html` on
+ each origin. None of the requests may be fetched. Check the engine log.
+ No second request may reach the engine.
First boot logs `PDF-HOST READY` or `PDF-HOST FAILED` in cloud-init output and,
where available, the serial console. A ready message confirms the health
diff --git a/infra/modules/pdf-host/pdf-init.sh.tftpl b/infra/modules/pdf-host/pdf-init.sh.tftpl
index 8f767a10a..87b211b92 100644
--- a/infra/modules/pdf-host/pdf-init.sh.tftpl
+++ b/infra/modules/pdf-host/pdf-init.sh.tftpl
@@ -165,7 +165,7 @@ docker run -d --name gotenberg --restart=always --network bridge \
--cap-drop=ALL --security-opt no-new-privileges \
-p "$ip:3000:3000" --dns "$resolver" \
'${gotenberg_image}' gotenberg --api-timeout='${api_timeout}' \
- --chromium-deny-list='(?i)^file:(?!//\/tmp/).*|^https?://(localhost([.:/]|$)|127\.|0\.0\.0\.0([:/]|$)|\[::1?\]([:/]|$)|(10\.|172\.(1[6-9]|2[0-9]|3[01])\.|192\.168\.)[^/:]+:3000([/?#]|$))' \
+ --chromium-deny-list='^file:(?!//\/tmp/).*|(?i:^https?://(([^/@]*@)?(([^/:]*\.)?localhost\.?|ip6-(localhost|loopback)|127\.[^/:]*|0\.0\.0\.0|\[(::1?|::ffff:(7f|127\.)[^\]]*)\])([:/]|$)|(10\.|172\.(1[6-9]|2[0-9]|3[01])\.|192\.168\.)[^/:]+:3000([/?#]|$)))' \
--chromium-deny-private-ips --api-download-from-deny-private-ips --webhook-disable
# This probe uses the published private address, not the container loopback.
curl --fail --silent --show-error --retry 30 --retry-connrefused --retry-delay 2 \
diff --git a/infra/modules/pdf-host/tests/pdf_host.tftest.hcl b/infra/modules/pdf-host/tests/pdf_host.tftest.hcl
index 78d224858..c06430366 100644
--- a/infra/modules/pdf-host/tests/pdf_host.tftest.hcl
+++ b/infra/modules/pdf-host/tests/pdf_host.tftest.hcl
@@ -103,7 +103,7 @@ run "container_config" {
strcontains(local.init_script, "--network bridge"),
strcontains(local.init_script, "-p \"$ip:3000:3000\" --dns \"$resolver\""),
strcontains(local.init_script, "gotenberg --api-timeout='55s'"),
- strcontains(local.init_script, "--chromium-deny-list='(?i)^file:(?!//\\/tmp/).*|"),
+ strcontains(local.init_script, "--chromium-deny-list='^file:(?!//\\/tmp/).*|"),
strcontains(local.init_script, "--chromium-deny-private-ips"),
strcontains(local.init_script, "--api-download-from-deny-private-ips"),
strcontains(local.init_script, "--webhook-disable"),
@@ -233,17 +233,39 @@ run "chromium_cannot_call_itself" {
"http://[::1]:3000/forms/chromium/convert/html", "http://[::]:3000/health",
"http://localhost:3000/health", "http://LOCALHOST./health", "http://0.0.0.0:3000/health",
"http://172.17.0.2:3000/forms/chromium/convert/html", "http://10.0.1.23:3000/health",
- ] : can(regex("(?i)${try(regex("--chromium-deny-list='[^']*[|](\\^https?[^']*)'", local.init_script)[0], "a^")}", url))
+ "http://foo.localhost:3000/health", "http://x.localhost./health",
+ "http://ip6-localhost:3000/health", "http://ip6-loopback:3000/health",
+ "http://[::ffff:7f00:1]:3000/health", "http://[::ffff:127.0.0.1]:3000/health",
+ "http://u@127.0.0.1:3000/health", "HTTP://LOCALHOST:3000/", "https://0.0.0.0/",
+ ] : can(regex(regex("--chromium-deny-list='[^']*?[|]([^']*)'", local.init_script)[0], url))
])
error_message = "Chromium must refuse loopback and the Gotenberg API, including the container bridge address"
}
assert {
condition = alltrue([
- for url in ["https://example.com/image.png", "http://example.com:8080/image.png", "http://example.com:3000/image.png", "http://93.184.215.14:3000/image.png"] :
- !can(regex("(?i)${try(regex("--chromium-deny-list='[^']*[|](\\^https?[^']*)'", local.init_script)[0], "a^")}", url))
+ for url in [
+ "https://example.com/image.png", "http://example.com:8080/image.png",
+ "http://example.com:3000/image.png", "http://93.184.215.14:3000/image.png",
+ "https://example.com/a.png", "https://localhost.example.com/x",
+ "https://my127.example.com/", "http://ip6-localhost.example.com/",
+ ] : !can(regex(regex("--chromium-deny-list='[^']*?[|]([^']*)'", local.init_script)[0], url))
])
error_message = "ordinary public HTTP and HTTPS assets must remain reachable"
}
+ assert {
+ # OpenTofu uses RE2; Gotenberg 8.39.0 uses regexp2 with lookahead.
+ # Pin the file arm and scope, then test its extracted exemption below.
+ condition = strcontains(local.init_script, "--chromium-deny-list='^file:(?!//\\/tmp/).*|(?i:^https?://")
+ error_message = "the default file rule must stay byte-identical with case-insensitivity scoped to HTTP"
+ }
+ assert {
+ condition = can(regex("^file:${regex("--chromium-deny-list='\\^file:\\(\\?!([^)]*)\\)\\.\\*", local.init_script)[0]}", "file:///tmp/index.html"))
+ error_message = "file:///tmp/index.html must be allowed by the file exemption"
+ }
+ assert {
+ condition = !can(regex("^file:${regex("--chromium-deny-list='\\^file:\\(\\?!([^)]*)\\)\\.\\*", local.init_script)[0]}", "file:///TMP/x"))
+ error_message = "file:///TMP/x must be denied by the case-sensitive file rule"
+ }
}
run "metadata_retry_is_bounded" {
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 755849c26..21226a4cc 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -62,4 +62,4 @@ plan14-root-reads-domain-registration-1.tsv 8e7126042fef8cc99899a29e9e06c22763a2
plan14-root-reads-edge-held-streams.tsv c61b055182bf84e822fab92199432bd2d462c268c03ead17c3cfa18f09bd82cd
plan14-root-reads-edge-protect-hard-block.tsv 3b6cd29b87d2728254936722ab45fdadcfbb8c1f5b74fdfa19d1921b9dfd1dbe
plan14-root-reads-edge-held-first-ping.tsv 3b6cd29b87d2728254936722ab45fdadcfbb8c1f5b74fdfa19d1921b9dfd1dbe
-plan14-root-reads-design-pdf-service.tsv 3c1c047d5919adccbab7d99a91056ace9a4d69a49ad9d6713aab6fd560b4ce25
+plan14-root-reads-design-pdf-service.tsv bcc149b3b39921018987ae5543414984d8fe10a9b2d12d94e2bed548f9d1c0a4
diff --git a/internal/provision/testdata/plan14-root-reads-design-pdf-service.tsv b/internal/provision/testdata/plan14-root-reads-design-pdf-service.tsv
index cb437c332..e2d518ab6 100644
--- a/internal/provision/testdata/plan14-root-reads-design-pdf-service.tsv
+++ b/internal/provision/testdata/plan14-root-reads-design-pdf-service.tsv
@@ -3,21 +3,21 @@
# 6 new dispositions: 0 reads re-frozen at their disposition with the claim, 6 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other.
@legacy bbe2f84ca2d68582fcbcb8f8e251fb8799429cc6989d404e6b12af376f050f7c infra/modules/pdf-host/main.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=OpenTofu module source defining the PDF engine box, security group and SSM-only role; never read by the CARLOS root binary or a box agent at runtime file:external@0 40594121a61d33e4c8c2058a101a6f01709c9b052d01e5ab62a0f7fc80f05b41
@legacy 077149cc35ce88d23aedd7c9f8c98a34808e9cc118635ed08969ba0cf0f4f906 infra/modules/pdf-host/outputs.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=OpenTofu module outputs for the PDF engine address, instance ID and security group ID; never read by the CARLOS root binary or a box agent at runtime file:external@0 45b004fd2b4134bbbae47a603083227be478ef3c9797c97a04a3417c0277d481
-@legacy 23460e3005efdab31283f8a178a02e88c1dd831c120a15e736e30aee0423caea infra/modules/pdf-host/pdf-init.sh.tftpl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=cloud-init template for the PDF box; add Chromium loopback and private engine-port denial, bounded metadata curl retries and bounded fence-unit restarts; Docker still requires and reloads the fence before starting; never read by the CARLOS root binary or a box agent at runtime file:external@0 a921c067173f7bd95bd222d37f25167cdd6f4f63ff69ef3635f9cad96ff06046
-@legacy 0941bf3ff4dcd1ba3ff4f0282f5b0ca858379b11f2c108998c5f9ba566046e69 infra/modules/pdf-host/tests/pdf_host.tftest.hcl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=mock-provider tests add loopback/private engine-port denial and public-asset acceptance, bounded metadata/fence retries and the Docker memory minimum; no live infrastructure calls; never read by the CARLOS root binary or a box agent at runtime file:external@0 a2dbcca1cb692588d7151836c5026e51be8ccdbb970a5c7d370fe9acdf89f7cf
+@legacy 68dbd15e2d1e09fb81b123e69ca7eb7d589bf0d715068caaaef3d685976a7ec2 infra/modules/pdf-host/pdf-init.sh.tftpl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=cloud-init template for the PDF box; extend Chromium denial to localhost subdomains, ip6 loopback aliases, mapped IPv6 loopback and userinfo, with case-insensitivity scoped to HTTP and the default file rule unchanged; retain private engine-port denial, bounded metadata/fence retries and Docker fence ordering; never read by the CARLOS root binary or a box agent at runtime file:external@0 23fa69a62f5eb334d22020a4cf6f3333acbef77d599263d69e4a8dc03870e740
+@legacy 00432992c8df130c960b06ae29f56b2a99c214579989e518e1afe907ba36a5d4 infra/modules/pdf-host/tests/pdf_host.tftest.hcl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=mock-provider tests cover loopback names, mapped IPv6 and userinfo, case-insensitive HTTP, public hostname boundaries and the case-sensitive file exemption; retain private engine-port, metadata/fence retry and Docker memory checks; no live infrastructure calls; never read by the CARLOS root binary or a box agent at runtime file:external@0 5bb3de478317a9326209d3260f37e1e6d9e20f8d15a0d4721192cf793949dc9d
@legacy c402b50151d1faeb4d78a87e0292b88115953c79286cc75587e0bf529fa5967d infra/modules/pdf-host/variables.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=OpenTofu module inputs now reject memory_max below 6 MiB while retaining whole MiB/GiB validation; never read by the CARLOS root binary or a box agent at runtime file:external@0 3919e0b520d36160608d4b2135e4494a686100e9f696b2896b3da4abd7310895
@legacy 828be666aef3fef1ab02f78e02137313f9d4b9e2f08c6d8c4bc136f19cdd0f9f infra/modules/pdf-host/versions.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=OpenTofu module tool and AWS provider version requirements; never read by the CARLOS root binary or a box agent at runtime file:external@0 bb3be812da255c0f031b2bfdfee462e4687de3681c742b529b55693a8875136b
system.go runSystem authority B,C,D,F,G,J4 rev3=census-ruling-self-serve-moves-1;identity=explicit operator CLI uid 0;basis=adds the lifetimes family to the system dispatch (carlos system lifetimes cutover, a console door call as the operator); every existing command branch unchanged;rev3=census-ruling-claims-cleanup-r2;basis=claims cleanup R2: drops the claims case (host.RunSystemClaims, deleted); every other branch unchanged; no read added;rev3=census-ruling-nearest-region-a;basis=adds the hosts-used family to the system dispatch (carlos system hosts-used status, one GET of a console door as the operator); every existing command branch unchanged; no read added;rev3=census-ruling-region-ha-p1a;basis=explicit operator CLI and root units, uid 0: drops the "join" case (host.RunSystemJoin, deleted with internal/host/joinroot.go, its only caller) and its line in the usage text; every other branch unchanged; no read added;rev3=census-ruling-named-unit-delivery-114;basis=the system verb dispatch gains named-units, routed to host.RunSystemNamedUnits; no read of its own;rev3=census-ruling-design-pdf-service;basis=add dispatch for carlos system pdf; no new reads 7f4861660abef9844dbeec756a68d7bb91a655d935b74acd807a85c61453e0f3
system.go systemVerb authority B,C,D,F,G,J4 rev3=census-ruling-self-serve-moves-1;identity=explicit operator CLI uid 0;basis=adds the lifetimes family to the system dispatch (carlos system lifetimes cutover, a console door call as the operator); every existing command branch unchanged;rev3=census-ruling-claims-cleanup-r2;basis=claims cleanup R2: drops "claims" from the verb list, so it now falls to the unknown-verb message; no read added;rev3=census-ruling-nearest-region-a;basis=adds "hosts-used" to the verb list, routed to runSystemHostsUsedVerb; no read added;rev3=census-ruling-region-ha-p1a;basis=explicit operator CLI and root units, uid 0: drops "join" from the verb list, so `carlos system join` now falls to the unknown-verb message; no read added;rev3=census-ruling-named-unit-delivery-114;basis=the known-verb list gains named-units; no read of its own;rev3=census-ruling-design-pdf-service;basis=add recognition for carlos system pdf; no new reads 6fa13065f4396cfac2f2c56b41aab51354cd0d9007b9d875542eef63a7fdb802
infra/modules/pdf-host/main.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=OpenTofu module source defining the PDF engine box, security group and SSM-only role; never read by the CARLOS root binary or a box agent at runtime file:external@0 40594121a61d33e4c8c2058a101a6f01709c9b052d01e5ab62a0f7fc80f05b41
infra/modules/pdf-host/outputs.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=OpenTofu module outputs for the PDF engine address, instance ID and security group ID; never read by the CARLOS root binary or a box agent at runtime file:external@0 45b004fd2b4134bbbae47a603083227be478ef3c9797c97a04a3417c0277d481
-infra/modules/pdf-host/pdf-init.sh.tftpl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=cloud-init template for the PDF box; add Chromium loopback and private engine-port denial, bounded metadata curl retries and bounded fence-unit restarts; Docker still requires and reloads the fence before starting; never read by the CARLOS root binary or a box agent at runtime file:external@0 a921c067173f7bd95bd222d37f25167cdd6f4f63ff69ef3635f9cad96ff06046
-infra/modules/pdf-host/tests/pdf_host.tftest.hcl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=mock-provider tests add loopback/private engine-port denial and public-asset acceptance, bounded metadata/fence retries and the Docker memory minimum; no live infrastructure calls; never read by the CARLOS root binary or a box agent at runtime file:external@0 a2dbcca1cb692588d7151836c5026e51be8ccdbb970a5c7d370fe9acdf89f7cf
+infra/modules/pdf-host/pdf-init.sh.tftpl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=cloud-init template for the PDF box; extend Chromium denial to localhost subdomains, ip6 loopback aliases, mapped IPv6 loopback and userinfo, with case-insensitivity scoped to HTTP and the default file rule unchanged; retain private engine-port denial, bounded metadata/fence retries and Docker fence ordering; never read by the CARLOS root binary or a box agent at runtime file:external@0 23fa69a62f5eb334d22020a4cf6f3333acbef77d599263d69e4a8dc03870e740
+infra/modules/pdf-host/tests/pdf_host.tftest.hcl external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=mock-provider tests cover loopback names, mapped IPv6 and userinfo, case-insensitive HTTP, public hostname boundaries and the case-sensitive file exemption; retain private engine-port, metadata/fence retry and Docker memory checks; no live infrastructure calls; never read by the CARLOS root binary or a box agent at runtime file:external@0 5bb3de478317a9326209d3260f37e1e6d9e20f8d15a0d4721192cf793949dc9d
infra/modules/pdf-host/variables.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=OpenTofu module inputs now reject memory_max below 6 MiB while retaining whole MiB/GiB validation; never read by the CARLOS root binary or a box agent at runtime file:external@0 3919e0b520d36160608d4b2135e4494a686100e9f696b2896b3da4abd7310895
infra/modules/pdf-host/versions.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-design-pdf-service;basis=OpenTofu module tool and AWS provider version requirements; never read by the CARLOS root binary or a box agent at runtime file:external@0 bb3be812da255c0f031b2bfdfee462e4687de3681c742b529b55693a8875136b
@coverage . aa87796b4b66f4ce9d20e6d571ef5f348258913fd71833fc75a88f109e41cf77
-@coverage infra/modules/pdf-host cf1322a254574bf20c8fc3da84f4b7979c6b0f07f6bd3925a7af0ab62512c30d
-@coverage infra/modules/pdf-host/tests 774a2938ff456990381b40e5317b2bc4faa2bfde95591edbe23b1d17bbcda8e7
+@coverage infra/modules/pdf-host e81254fcbc110962c9e32f3449f2e2f9b13f8d84c42a4102b708623609152f46
+@coverage infra/modules/pdf-host/tests c2cf960befb47aeb065daf09a5fe5a01cabc95da36af1ce215b7d9df0fc1ac92
@coverage internal/plans 626020904e3d1e996006b968cb8dba8dfcf80b3022160b7d02060040d830f3ea
@coverage internal/release a8ada352dd633d1b211e81e4c44fba85d295a44c38f1995696022628083875dc
@coverage internal/svcrole e910500ba710dd884ca2f4cf9100a8e1a9573952555554514b97375796937beb