Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/remediation/ban/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ban

import (
"html"
"net/url"

"github.com/dropmorepackets/haproxy-go/pkg/encoding"
Expand Down Expand Up @@ -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))
}
6 changes: 1 addition & 5 deletions lua/crowdsec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ end

local runtime = {}

local function html_escape(s)
return s:gsub('&', '&amp;'):gsub('<', '&lt;'):gsub('>', '&gt;'):gsub('"', '&quot;')
end

-- Loads the configuration
local function init()
BAN_TEMPLATE_PATH = os.getenv("CROWDSEC_BAN_TEMPLATE_PATH")
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion templates/ban-with-contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</svg>
<h1 class="text-xl md:text-2xl lg:text-3xl xl:text-4xl"> CrowdSec Access Forbidden</h1>
<p class="lg:text-xl md:text-lg"> You are unable to visit the website.</p>
<a href="%[var(txn.crowdsec.contact_us_url),html]" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
<a href="%[var(txn.crowdsec.contact_us_url)]" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Contact Us
</a>
</div>
Expand Down
Loading