diff --git a/internal/remediation/ban/root.go b/internal/remediation/ban/root.go index 323518a..d769353 100644 --- a/internal/remediation/ban/root.go +++ b/internal/remediation/ban/root.go @@ -1,6 +1,7 @@ package ban import ( + "html" "net/url" "github.com/dropmorepackets/haproxy-go/pkg/encoding" @@ -29,5 +30,5 @@ func (b *Ban) InjectKeyValues(writer *encoding.ActionWriter) { contactURL = "" } } - _ = writer.SetString(encoding.VarScopeTransaction, "contact_us_url", contactURL) + _ = writer.SetString(encoding.VarScopeTransaction, "contact_us_url", html.EscapeString(contactURL)) } diff --git a/lua/crowdsec.lua b/lua/crowdsec.lua index 0c1442b..d457f8f 100644 --- a/lua/crowdsec.lua +++ b/lua/crowdsec.lua @@ -53,10 +53,6 @@ end local runtime = {} -local function html_escape(s) - return s:gsub('&', '&'):gsub('<', '<'):gsub('>', '>'):gsub('"', '"') -end - -- Loads the configuration local function init() BAN_TEMPLATE_PATH = os.getenv("CROWDSEC_BAN_TEMPLATE_PATH") @@ -137,7 +133,7 @@ function runtime.Handle(txn) if remediation == "ban" then reply:set_body(runtime.ban.render({ - ["contact_us_url"]=html_escape(get_txn_var(txn, "crowdsec.contact_us_url")), + ["contact_us_url"]=get_txn_var(txn, "crowdsec.contact_us_url"), })) end diff --git a/templates/ban-with-contact.html b/templates/ban-with-contact.html index 9ddb7b4..e794c63 100644 --- a/templates/ban-with-contact.html +++ b/templates/ban-with-contact.html @@ -17,7 +17,7 @@

CrowdSec Access Forbidden

You are unable to visit the website.

- + Contact Us