Hugo v0.162.0 がリリースされた【Security fix あり】
Hugo v0.162.0 がリリースされた。
Go コンパイラおよび関連パッケージのセキュリティ・アップデートがあるのはいつものことなのだが,今回は注意すべき修正がある。
Security fixes and hardening in Hugo
The following changes either fix a concrete issue or reduce the default attack surface of
hugobuilds.
- Disallow
text/htmlcontent files by default (e41a064). A newsecurity.allowContentpolicy gates which content media types may be used for pages under/content.text/htmlis denied by default; sites that rely on hand-authored or adapter-emitted HTML content can opt back in withsecurity.allowContent = ['.*'].- Re-check
security.http.urlson every redirect hop inresources.GetRemote(86fbb0f).- Reject symlinked entries in
resources.Get(f8b5fa0).
このうち,最初の項目にまんまと引っかかった。 こんな感じ:
ERROR error building site: assemble: failed to create page from pageMetaSource
/remark/2015/gnupg-2-1-8: "/path/to/content/remark/2015/gnupg-2-1-8.html:1:1":
access denied: "text/html" is not whitelisted in policy "security.allowContent";
the current security configuration is:
[security]
allowContent = ['! ^text/html$']
enableInlineShortcodes = false
...
どうも既定では HTML ファイルを拒否する設定になったらしい。
それならば HTML を許可すればいいだろうと, “!” を取って
[security]
allowContent = ["^text/html$"]
と hugo.toml に書いたら markdown ファイルが全拒否になってしまった(笑)。HTML と markdown のみを許可するには
[security]
allowContent = ["^text/markdown$", "^text/html$"]
などとする必要がある。 ちなみに Hugo では
Create your content using Markdown, HTML, Emacs Org Mode, AsciiDoc, Pandoc, or reStructuredText.
Content formats
と多様なフォーマットに対応している。
この中で HTML 形式を受け入れるのは(malware を埋め込まれたりとか)リスクが高いと判断して安全側に倒したものと思われる。
実運用では security.allowContent に,実際に使用するドキュメントフォーマットのみを列挙するのが正しいのだろう。
エラーの出た gnupg-2-1-8.html はこのブログにおける最初の記事で,元々は Movable Type 用に書いた記事で「そのまま読み込ませてコンパイルできるかなぁ」と試してみた記事だった。
記事本文の HTML 記述はともかく front matter を整えるのが面倒くさそうなので旧ブログからの移行は諦めたが。
今なら変換ツールを AI に書かせたんだろうなぁ(笑)
最近は GitHub Copilot に Hugo のアップデートと redeploy をさせているのだが,今回の障害の分析と対処はすべてお任せで作業を完遂できた。 「Hugo のマイナーバージョンアップは問題が出やすいから気をつけて」と指示に添えたのが功を奏したようだ。 自力でやったら悩みまくって,ドキュメントを調べまくって30分くらい時間を無駄にしてただろう。 いい時代になったものである。
