config: escape % signs in local reply format string (#5460)

Since v0.26, Pomerium configures Envoy to use a custom HTML error page
format string for most errors served by Envoy itself. This format string
uses %COMMAND% directives to include details about the error.

The HTML error page template also includes any branding options set via
the corresponding Enterprise settings. We need to ensure that any %
signs in the branding options strings are escaped to %% so that Envoy
will not interpret them as the start of a %COMMAND% directive, which
could lead to Envoy rejecting the format string as invalid.
This commit is contained in:
Kenneth Jenkins 2025-02-03 14:31:06 -08:00 committed by GitHub
parent 34c25442ff
commit efe3cef2e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 76 additions and 6 deletions

View file

@ -56,13 +56,19 @@ func (b *Builder) buildLocalReplyConfig(
headers = toEnvoyHeaders(options.GetSetResponseHeaders())
}
data := map[string]any{
"status": "%RESPONSE_CODE%",
"statusText": "%RESPONSE_CODE_DETAILS%",
"requestId": "%STREAM_ID%",
"responseFlags": "%RESPONSE_FLAGS%",
}
data := make(map[string]any)
httputil.AddBrandingOptionsToMap(data, options.BrandingOptions)
for k, v := range data {
// Escape any % signs in the branding options data, as Envoy will
// interpret the page output as a substitution format string.
if s, ok := v.(string); ok {
data[k] = strings.ReplaceAll(s, "%", "%%")
}
}
data["status"] = "%RESPONSE_CODE%"
data["statusText"] = "%RESPONSE_CODE_DETAILS%"
data["requestId"] = "%STREAM_ID%"
data["responseFlags"] = "%RESPONSE_FLAGS%"
bs, err := ui.RenderPage("Error", "Error", data)
if err != nil {