Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sanitize url before sending #22

Closed
wants to merge 2 commits into from
Closed
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
16 changes: 16 additions & 0 deletions nic.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
local http = ...

local function char_to_hex(c)
return string.format("%%%02X", string.byte(c))
end

local function safe_url(url)
url = url:gsub("%s+", "%%20") -- space characters
url = url:gsub("%%$", "%%25") -- percent at the end of the url
url = url:gsub("%%(%x?%X)", "%%25%1") -- percents that are not escapes
url = url:gsub("\\", "/") -- backslash to forward slash
url = url:gsub("[^%w:/%?#%[%]@!%$&'%(%)%*%+,;=%-%._~%%]", char_to_hex) -- everything else unsafe
return url
end

minetest.register_node("digistuff:nic", {
description = "Digilines NIC",
groups = {cracky=3},
Expand Down Expand Up @@ -62,6 +76,8 @@ minetest.register_node("digistuff:nic", {
-- not supported
return
end
-- sanitize url
url = safe_url(url)
http.fetch({
url = url,
timeout = 5,
Expand Down