Skip to content

feat(web): self-host web fonts so no page loads from Google - #905

Merged
artempartos merged 4 commits into
developfrom
feature/353-self-host-web-fonts
Nov 30, 2026
Merged

artempartos merged 4 commits into
developfrom
feature/353-self-host-web-fonts

Conversation

@aixle-com

@aixle-com aixle-com Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Why

Every Flow page loaded Inter, JetBrains Mono and Spline Sans Mono from fonts.googleapis.com / fonts.gstatic.com, so each visitor's browser sent its IP address to Google (a GDPR concern for EU customers). Fonts are now served from our own origin.

Card: https://flow.aixle.com/company/projects/56/board?n=353

What changed

  • public/fonts/v1/: the OFL variable woff2 files from @fontsource-variable/{inter,jetbrains-mono,spline-sans-mono} 5.3.0 (same subsets Google serves: Inter and JetBrains Mono latin/latin-ext/cyrillic/cyrillic-ext/greek/vietnamese, plus greek-ext for Inter; Spline Sans Mono latin/latin-ext), one fonts.css with the family names the Mantine theme uses (Inter, JetBrains Mono, Spline Sans Mono), the moved "Inter Fallback" metric override, the OFL texts and a README. v1 is the cache buster (public/ is cached for a year); a font update goes to v2/. ~420 KB in total.
  • shared/_web_fonts: a preload of the Inter latin face plus the stylesheet, same-origin paths. The families: local is gone and the 6 callers render it without arguments.
  • Static error pages (public/400|406-unsupported-browser|422|500.html): link /fonts/v1/fonts.css instead of Google and drop their inline fallback copy.
  • Mailer layout: no web font link; FONT_SANS fallback stack and the Outlook Segoe UI pin stay.
  • CSP: font-src is this origin, the asset host and data:; style-src is this origin, the asset host and 'unsafe-inline'. :https is dropped from both, since it would still allow the Google hosts. Staging and production set CSP_ENFORCE, so there the new policy blocks from the first deploy rather than reporting: watch Sentry CSP issues after it. No external stylesheet or font is left in app/ or public/.
  • shared/_web_fonts declares strict locals (), so a leftover families: call fails instead of being ignored.
  • THIRD-PARTY-LICENSES.md row, CHANGELOG.md entry (no product area: the change spans every page rather than one area).

Tests

  • test/integration/self_hosted_fonts_test.rb (new): landing, privacy policy, login (Inertia layout), admin users page, 404 and public asset viewer have no googleapis/gstatic and link /fonts/v1/fonts.css.
  • test/lib/self_hosted_font_files_test.rb (new): no view/frontend file/static page references Google font hosts; every url() in fonts.css and the preload point to existing files; family names; each static error page links the stylesheet.
  • test/integration/content_security_policy_test.rb: font-src is exactly 'self' data:, no Google hosts, no https: in style-src.
  • test/mailers/password_mailer_test.rb: the email has no Google link and keeps the FONT_SANS stack.

Checks

  • ❌ Not run locally: Docker is not available in the agent container, so bin/rails test, make lint_check_all (rubocop, brakeman, eslint, tsc) and make check_all did not run. CI is the first run of the new and changed tests.
  • ✅ Ran: rg 'fonts\.(googleapis|gstatic)' over app/, public/, config/: no matches left; every url() in fonts.css resolves to a committed file (checked with a script).

🤖 Generated with Claude Code

@aixle-com

aixle-com Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Code Review — round 1 — PASS

No critical issues. The change follows the Tech Design point by point:

  • All 15 woff2 files are committed under public/fonts/v1/. Each one has a valid wOF2 header and the subsets Google serves.
  • fonts.css keeps the family names mantineTheme.ts uses and holds the single "Inter Fallback" rule.
  • The partial is a same-origin preload plus the stylesheet. The 6 callers are updated, and the 4 static error pages link /fonts/v1/fonts.css.
  • The mailer link is gone.
  • CSP: font-src 'self' data:, and style-src is now self + asset host + unsafe-inline, without https:.
  • OFL texts, the README, the THIRD-PARTY-LICENSES row and the CHANGELOG entry are all there.
  • Commit messages follow Conventional Commits.

The main behavior has tests at the layers the Tech Design asks for:

  • integration, for the landing, legal, login, admin, 404 and public-asset pages and for the CSP header;
  • lib checks for no Google URLs, every referenced file existing, the family names and the static pages;
  • a mailer test.

All factories, traits, route helpers and test seams these tests use exist on develop. I did not run the suite (no Docker here), so CI is the first run.

Non-critical suggestions

  1. app/helpers/mailer_helper.rb:4-5: the comment says Apple Mail, Outlook for Mac, Thunderbird and Samsung Mail "load Inter". That was true only because of the Google link this PR removes. Now Inter applies only where it is installed locally. Reword or delete the comment, as CLAUDE.md asks ("delete it with the code it describes").
  2. test/lib/self_hosted_font_files_test.rb:24: assert_equal 15, urls.size adds no proof beyond the existence check below it, and it breaks on any v2/ change. Consider dropping it or deriving the count from the files on disk.
  3. CHANGELOG.md:21: the entry has no product-area prefix. That is acceptable for a change that touches every page. If the taxonomy has a fitting general area, consider adding it.
  4. After deploy, watch the CSP reports in Sentry for stylesheets now blocked by the narrower style-src (in development the Vite dev server, in production any third-party stylesheet) before anyone sets CSP_ENFORCE. The Tech Design already lists this risk.

@dvislov
dvislov marked this pull request as ready for review November 30, 2026 12:14
Aixle Flow and others added 3 commits November 30, 2026 16:14
The OFL-licensed variable woff2 files from @fontsource-variable 5.3.0,
with the same unicode subsets Google Fonts serves, and one stylesheet
under the family names the frontend theme uses. The v1 path segment is
the cache buster: public/ is served with a one-year max-age.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Dmitry Vislov <[email protected]>
Every page, the static error pages and the admin panel sent each
visitor's IP address to Google for fonts. They now link
/fonts/v1/fonts.css, the mailer links no web font, and the CSP drops
the Google hosts and the blanket https: source from font-src and
style-src.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Dmitry Vislov <[email protected]>
The Google-font scan read every file under app/frontend as UTF-8 and
raised on the agent-logo PNGs. Read them with File.binread instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Dmitry Vislov <[email protected]>
@dvislov
dvislov force-pushed the feature/353-self-host-web-fonts branch from cb1e7ae to 2ff2ebe Compare November 30, 2026 12:15
@dvislov
dvislov requested a review from artempartos November 30, 2026 12:15
A font bundled by Vite is served from the asset host in production, where the
policy is enforced, so font-src matches script-src and style-src. The partial
takes no locals now; strict locals make a leftover `families:` call fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit ebe55a8 into develop Nov 30, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant