Verified Commit 7e366de7 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

Bug 41116: Normalize system fonts.

System fonts are an enormous fingerprinting vector.
Even with font allow lists and with our custom configuration on Linux,
which counter metrics measurements, getComputedStyle leaks several
details.
This patch counters both these kinds of attacks.
parent 61705207
Loading
Loading
Loading
Loading
+8 −0
Changes for gfx/thebes/gfxPlatformFontList.cpp: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1901,6 +1901,14 @@ static void GetSystemUIFontFamilies([[maybe_unused]] nsAtom* aLangGroup,
  nsFont systemFont;
  gfxFontStyle fontStyle;
  nsAutoString systemFontName;
  if (nsContentUtils::ShouldResistFingerprinting()) {
#ifdef XP_MACOSX
    *aFamilies.AppendElement() = "-apple-system"_ns;
#else
    *aFamilies.AppendElement() = "sans-serif"_ns;
#endif
    return;
  }
  if (!LookAndFeel::GetFont(StyleSystemFont::Menu, systemFontName, fontStyle)) {
    return;
  }
+7 −1
Changes for layout/base/nsLayoutUtils.cpp: 7 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -9564,7 +9564,13 @@ void nsLayoutUtils::ComputeSystemFont(nsFont* aSystemFont,
                                      const Document* aDocument) {
  gfxFontStyle fontStyle;
  nsAutoString systemFontName;
  if (!LookAndFeel::GetFont(aFontID, systemFontName, fontStyle)) {
  if (aDocument->ShouldResistFingerprinting()) {
#ifdef XP_MACOSX
    systemFontName = u"-apple-system"_ns;
#else
    systemFontName = u"sans-serif"_ns;
#endif
  } else if (!LookAndFeel::GetFont(aFontID, systemFontName, fontStyle)) {
    return;
  }
  systemFontName.Trim("\"'");