diff --git a/themes/src/main/resources/theme/base/account/template.ftl b/themes/src/main/resources/theme/base/account/template.ftl
index e49c664a6e1..d372ad5b176 100644
--- a/themes/src/main/resources/theme/base/account/template.ftl
+++ b/themes/src/main/resources/theme/base/account/template.ftl
@@ -70,7 +70,7 @@
<#if message.type=='success' >#if>
<#if message.type=='error' >#if>
- ${message.summary?no_esc}
+ ${kcSanitize(message.summary)?no_esc}
#if>
diff --git a/themes/src/main/resources/theme/base/email/html/email-test.ftl b/themes/src/main/resources/theme/base/email/html/email-test.ftl
index d5d18b73cd1..3a522728f46 100644
--- a/themes/src/main/resources/theme/base/email/html/email-test.ftl
+++ b/themes/src/main/resources/theme/base/email/html/email-test.ftl
@@ -1,5 +1,5 @@
-${msg("emailTestBodyHtml",realmName)?no_esc}
+${kcSanitize(msg("emailTestBodyHtml",realmName))?no_esc}
diff --git a/themes/src/main/resources/theme/base/email/html/email-verification-with-code.ftl b/themes/src/main/resources/theme/base/email/html/email-verification-with-code.ftl
index b4a01c9eee9..66e89258743 100644
--- a/themes/src/main/resources/theme/base/email/html/email-verification-with-code.ftl
+++ b/themes/src/main/resources/theme/base/email/html/email-verification-with-code.ftl
@@ -1,5 +1,5 @@
-${msg("emailVerificationBodyCodeHtml",code)?no_esc}
+${kcSanitize(msg("emailVerificationBodyCodeHtml",code))?no_esc}
diff --git a/themes/src/main/resources/theme/base/email/html/email-verification.ftl b/themes/src/main/resources/theme/base/email/html/email-verification.ftl
index bd371d9db1f..dacabd2525e 100644
--- a/themes/src/main/resources/theme/base/email/html/email-verification.ftl
+++ b/themes/src/main/resources/theme/base/email/html/email-verification.ftl
@@ -1,5 +1,5 @@
-${msg("emailVerificationBodyHtml",link, linkExpiration, realmName, linkExpirationFormatter(linkExpiration))?no_esc}
+${kcSanitize(msg("emailVerificationBodyHtml",link, linkExpiration, realmName, linkExpirationFormatter(linkExpiration)))?no_esc}
diff --git a/themes/src/main/resources/theme/base/email/html/event-login_error.ftl b/themes/src/main/resources/theme/base/email/html/event-login_error.ftl
index 68ba81d6cb7..022c024dae4 100644
--- a/themes/src/main/resources/theme/base/email/html/event-login_error.ftl
+++ b/themes/src/main/resources/theme/base/email/html/event-login_error.ftl
@@ -1,5 +1,5 @@
-${msg("eventLoginErrorBodyHtml",event.date,event.ipAddress)?no_esc}
+${kcSanitize(msg("eventLoginErrorBodyHtml",event.date,event.ipAddress))?no_esc}
diff --git a/themes/src/main/resources/theme/base/email/html/event-remove_totp.ftl b/themes/src/main/resources/theme/base/email/html/event-remove_totp.ftl
index e5ddadbac85..9a56ed387c6 100644
--- a/themes/src/main/resources/theme/base/email/html/event-remove_totp.ftl
+++ b/themes/src/main/resources/theme/base/email/html/event-remove_totp.ftl
@@ -1,5 +1,5 @@
-${msg("eventRemoveTotpBodyHtml",event.date, event.ipAddress)?no_esc}
+${kcSanitize(msg("eventRemoveTotpBodyHtml",event.date, event.ipAddress))?no_esc}
diff --git a/themes/src/main/resources/theme/base/email/html/event-update_password.ftl b/themes/src/main/resources/theme/base/email/html/event-update_password.ftl
index dd5fda31ae1..27825c72df0 100644
--- a/themes/src/main/resources/theme/base/email/html/event-update_password.ftl
+++ b/themes/src/main/resources/theme/base/email/html/event-update_password.ftl
@@ -1,5 +1,5 @@
-${msg("eventUpdatePasswordBodyHtml",event.date, event.ipAddress)?no_esc}
+${kcSanitize(msg("eventUpdatePasswordBodyHtml",event.date, event.ipAddress))?no_esc}
diff --git a/themes/src/main/resources/theme/base/email/html/event-update_totp.ftl b/themes/src/main/resources/theme/base/email/html/event-update_totp.ftl
index 050abab7ea0..3ed37c38b6e 100644
--- a/themes/src/main/resources/theme/base/email/html/event-update_totp.ftl
+++ b/themes/src/main/resources/theme/base/email/html/event-update_totp.ftl
@@ -1,5 +1,5 @@
-${msg("eventUpdateTotpBodyHtml",event.date, event.ipAddress)?no_esc}
+${kcSanitize(msg("eventUpdateTotpBodyHtml",event.date, event.ipAddress))?no_esc}
diff --git a/themes/src/main/resources/theme/base/email/html/executeActions.ftl b/themes/src/main/resources/theme/base/email/html/executeActions.ftl
index 6510dfc1160..4c837bcbb64 100755
--- a/themes/src/main/resources/theme/base/email/html/executeActions.ftl
+++ b/themes/src/main/resources/theme/base/email/html/executeActions.ftl
@@ -4,6 +4,6 @@
-${msg("executeActionsBodyHtml",link, linkExpiration, realmName, requiredActionsText, linkExpirationFormatter(linkExpiration))?no_esc}
+${kcSanitize(msg("executeActionsBodyHtml",link, linkExpiration, realmName, requiredActionsText, linkExpirationFormatter(linkExpiration)))?no_esc}
diff --git a/themes/src/main/resources/theme/base/email/html/identity-provider-link.ftl b/themes/src/main/resources/theme/base/email/html/identity-provider-link.ftl
index fff38fc330e..8b67968e17e 100644
--- a/themes/src/main/resources/theme/base/email/html/identity-provider-link.ftl
+++ b/themes/src/main/resources/theme/base/email/html/identity-provider-link.ftl
@@ -1,5 +1,5 @@
-${msg("identityProviderLinkBodyHtml", identityProviderAlias, realmName, identityProviderContext.username, link, linkExpiration, linkExpirationFormatter(linkExpiration))?no_esc}
+${kcSanitize(msg("identityProviderLinkBodyHtml", identityProviderAlias, realmName, identityProviderContext.username, link, linkExpiration, linkExpirationFormatter(linkExpiration)))?no_esc}
\ No newline at end of file
diff --git a/themes/src/main/resources/theme/base/email/html/password-reset.ftl b/themes/src/main/resources/theme/base/email/html/password-reset.ftl
index e56ae1ea897..b2840b63002 100755
--- a/themes/src/main/resources/theme/base/email/html/password-reset.ftl
+++ b/themes/src/main/resources/theme/base/email/html/password-reset.ftl
@@ -1,5 +1,5 @@
-${msg("passwordResetBodyHtml",link, linkExpiration, realmName, linkExpirationFormatter(linkExpiration))?no_esc}
+${kcSanitize(msg("passwordResetBodyHtml",link, linkExpiration, realmName, linkExpirationFormatter(linkExpiration)))?no_esc}
\ No newline at end of file
diff --git a/themes/src/main/resources/theme/base/login/error.ftl b/themes/src/main/resources/theme/base/login/error.ftl
index 23468c56d7d..f237f7e0b46 100755
--- a/themes/src/main/resources/theme/base/login/error.ftl
+++ b/themes/src/main/resources/theme/base/login/error.ftl
@@ -6,7 +6,7 @@
#if>
diff --git a/themes/src/main/resources/theme/base/login/info.ftl b/themes/src/main/resources/theme/base/login/info.ftl
index 8eff9c36220..fc3a1aa310c 100755
--- a/themes/src/main/resources/theme/base/login/info.ftl
+++ b/themes/src/main/resources/theme/base/login/info.ftl
@@ -12,11 +12,11 @@
<#if skipLink??>
<#else>
<#if pageRedirectUri??>
-
${msg("backToApplication")?no_esc}
+
${kcSanitize(msg("backToApplication"))?no_esc}
<#elseif actionUri??>
-
${msg("proceedWithAction")?no_esc}
+
${kcSanitize(msg("proceedWithAction"))?no_esc}
<#elseif client.baseUrl??>
-
${msg("backToApplication")?no_esc}
+
${kcSanitize(msg("backToApplication"))?no_esc}
#if>
#if>
diff --git a/themes/src/main/resources/theme/base/login/login-reset-password.ftl b/themes/src/main/resources/theme/base/login/login-reset-password.ftl
index 79481bce73d..720c274ebfa 100755
--- a/themes/src/main/resources/theme/base/login/login-reset-password.ftl
+++ b/themes/src/main/resources/theme/base/login/login-reset-password.ftl
@@ -16,7 +16,7 @@