Skip to content

Commit 427792a

Browse files
fix: validate google fonts host when resolving material symbols font urls
Agent-Logs-Url: https://github.com/MudBlazor/MudBlazor.Icons/sessions/fc7706eb-3126-40d0-a98c-7a41f446deb0 Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
1 parent eb9e722 commit 427792a

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/GoogleMaterialDesignIconsGenerator/Service/IconHttpClientService.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,18 @@ private static Uri ResolveWoff2Url(string cssContent, string familyName)
9595
throw new InvalidOperationException($"Failed to resolve .woff2 URL from Google Fonts CSS for '{familyName}'.");
9696
}
9797

98-
return new Uri(match.Groups["href"].Value, UriKind.Absolute);
98+
if (!Uri.TryCreate(match.Groups["href"].Value, UriKind.Absolute, out var uri))
99+
{
100+
throw new InvalidOperationException($"Resolved an invalid .woff2 URL from Google Fonts CSS for '{familyName}'.");
101+
}
102+
103+
if (!uri.Scheme.Equals(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) ||
104+
!uri.Host.Equals("fonts.gstatic.com", StringComparison.OrdinalIgnoreCase))
105+
{
106+
throw new InvalidOperationException($"Resolved an unexpected .woff2 URL host '{uri.Host}' from Google Fonts CSS for '{familyName}'.");
107+
}
108+
109+
return uri;
99110
}
100111

101112
public void Dispose()

0 commit comments

Comments
 (0)