mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-25 14:08:31 +01:00
Merge pull request #5271 from Menshin/html_sanitization
Text input sanitization (take 1)
This commit is contained in:
+17
-15
@@ -25,19 +25,6 @@
|
||||
* Text sanitization
|
||||
*/
|
||||
|
||||
//this proc strips html properly, but it's not lazy like the other procs.
|
||||
//this means that it doesn't just remove < and > and call it a day. seriously, who the fuck thought that would be useful.
|
||||
/proc/strip_html_properly(var/input)
|
||||
var/opentag = 1 //These store the position of < and > respectively.
|
||||
var/closetag = 1
|
||||
while(1)
|
||||
opentag = findtext(input, "<")
|
||||
closetag = findtext(input, ">")
|
||||
if(!closetag || !opentag)
|
||||
break
|
||||
input = copytext(input, 1, opentag) + copytext(input, (closetag + 1))
|
||||
return input
|
||||
|
||||
//Simply removes < and > and limits the length of the message
|
||||
/proc/strip_html_simple(var/t,var/limit=MAX_MESSAGE_LEN)
|
||||
var/list/strip_chars = list("<",">")
|
||||
@@ -86,10 +73,10 @@
|
||||
else non_whitespace = 1
|
||||
if(non_whitespace) return text //only accepts the text if it has some non-spaces
|
||||
|
||||
// Used to get a sanitized input.
|
||||
// Used to get a properly sanitized input, of max_length
|
||||
/proc/stripped_input(var/mob/user, var/message = "", var/title = "", var/default = "", var/max_length=MAX_MESSAGE_LEN)
|
||||
var/name = input(user, message, title, default)
|
||||
return strip_html_simple(name, max_length)
|
||||
return strip_html_properly(name, max_length)
|
||||
|
||||
//Filters out undesirable characters from names
|
||||
/proc/reject_bad_name(var/t_in, var/allow_numbers=0, var/max_length=MAX_NAME_LEN)
|
||||
@@ -155,6 +142,21 @@
|
||||
|
||||
return t_out
|
||||
|
||||
//this proc strips html properly, but it's not lazy like the other procs.
|
||||
//this means that it doesn't just remove < and > and call it a day. seriously, who the fuck thought that would be useful.
|
||||
//also limit the size of the input, if specified to
|
||||
/proc/strip_html_properly(var/input,var/max_length=MAX_MESSAGE_LEN)
|
||||
var/opentag = 1 //These store the position of < and > respectively.
|
||||
var/closetag = 1
|
||||
while(1)
|
||||
opentag = findtext(input, "<")
|
||||
closetag = findtext(input, ">")
|
||||
if(!closetag || !opentag)
|
||||
break
|
||||
input = copytext(input, 1, opentag) + copytext(input, (closetag + 1))
|
||||
if(max_length)
|
||||
input = copytext(input,1,max_length)
|
||||
return input
|
||||
|
||||
/*
|
||||
* Text searches
|
||||
|
||||
@@ -371,4 +371,4 @@ var/list/pointers = list()
|
||||
for(var/d in data)
|
||||
var/val = data[d]
|
||||
if(istext(val))
|
||||
data[d] = strip_html_simple(val)
|
||||
data[d] = strip_html_properly(val)
|
||||
|
||||
@@ -268,9 +268,9 @@ text("<A href='?src=\ref[src];power=1'>[on ? "On" : "Off"]</A>"))
|
||||
qdel(src)
|
||||
|
||||
else if (istype(W, /obj/item/weapon/pen))
|
||||
var/t = copytext(stripped_input(user, "Enter new robot name", name, created_name),1,MAX_NAME_LEN)
|
||||
var/t = stripped_input(user, "Enter new robot name", name, created_name,MAX_NAME_LEN)
|
||||
if (!t)
|
||||
return
|
||||
if (!in_range(src, usr) && loc != usr)
|
||||
return
|
||||
created_name = t
|
||||
created_name = t
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
radio_frequency = SEC_FREQ
|
||||
bot_type = SEC_BOT
|
||||
bot_filter = RADIO_SECBOT
|
||||
/
|
||||
|
||||
//List of weapons that secbots will not arrest for
|
||||
var/safe_weapons = list(\
|
||||
/obj/item/weapon/gun/energy/laser/bluetag,\
|
||||
@@ -560,7 +560,7 @@ Auto Patrol[]"},
|
||||
..()
|
||||
|
||||
if(istype(W, /obj/item/weapon/pen))
|
||||
var/t = copytext(stripped_input(user, "Enter new robot name", name, created_name),1,MAX_NAME_LEN)
|
||||
var/t = stripped_input(user, "Enter new robot name", name, created_name,MAX_NAME_LEN)
|
||||
if(!t) return
|
||||
if(!in_range(src, usr) && loc != usr) return
|
||||
created_name = t
|
||||
|
||||
@@ -503,7 +503,7 @@ obj/machinery/bot/floorbot/process_scan(var/scan_target)
|
||||
qdel(src)
|
||||
|
||||
else if (istype(W, /obj/item/weapon/pen))
|
||||
var/t = copytext(stripped_input(user, "Enter new robot name", name, created_name),1,MAX_NAME_LEN)
|
||||
var/t = stripped_input(user, "Enter new robot name", name, created_name,MAX_NAME_LEN)
|
||||
if (!t)
|
||||
return
|
||||
if (!in_range(src, usr) && loc != usr)
|
||||
@@ -522,11 +522,10 @@ obj/machinery/bot/floorbot/process_scan(var/scan_target)
|
||||
user.unEquip(src, 1)
|
||||
qdel(src)
|
||||
else if (istype(W, /obj/item/weapon/pen))
|
||||
var/t = stripped_input(user, "Enter new robot name", name, created_name)
|
||||
|
||||
var/t = stripped_input(user, "Enter new robot name", name, created_name,MAX_NAME_LEN)
|
||||
if (!t)
|
||||
return
|
||||
if (!in_range(src, usr) && loc != usr)
|
||||
return
|
||||
|
||||
created_name = t
|
||||
created_name = t
|
||||
|
||||
@@ -557,7 +557,7 @@
|
||||
/obj/item/weapon/firstaid_arm_assembly/attackby(obj/item/weapon/W as obj, mob/user as mob)
|
||||
..()
|
||||
if(istype(W, /obj/item/weapon/pen))
|
||||
var/t = copytext(stripped_input(user, "Enter new robot name", name, created_name),1,MAX_NAME_LEN)
|
||||
var/t = stripped_input(user, "Enter new robot name", name, created_name,MAX_NAME_LEN)
|
||||
if (!t)
|
||||
return
|
||||
if (!in_range(src, usr) && loc != usr)
|
||||
|
||||
@@ -449,7 +449,7 @@ Auto Patrol: []"},
|
||||
qdel(src)
|
||||
|
||||
else if(istype(I, /obj/item/weapon/pen))
|
||||
var/t = copytext(stripped_input(user, "Enter new robot name", name, created_name),1,MAX_NAME_LEN)
|
||||
var/t = stripped_input(user, "Enter new robot name", name, created_name,MAX_NAME_LEN)
|
||||
if(!t)
|
||||
return
|
||||
if(!in_range(src, usr) && loc != usr)
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
if(istype(W, /obj/item/weapon/screwdriver))
|
||||
playsound(src.loc, 'sound/items/Screwdriver.ogg', 50, 1)
|
||||
|
||||
var/input = strip_html(input(usr, "Which networks would you like to connect this camera to? Seperate networks with a comma. No Spaces!\nFor example: SS13,Security,Secret ", "Set Network", "SS13"))
|
||||
var/input = stripped_input(usr, "Which networks would you like to connect this camera to? Seperate networks with a comma. No Spaces!\nFor example: SS13,Security,Secret ", "Set Network", "SS13")
|
||||
if(!input)
|
||||
usr << "No input found please hang up and try your call again."
|
||||
return
|
||||
@@ -99,7 +99,7 @@
|
||||
|
||||
C.network = tempnetwork
|
||||
var/area/A = get_area_master(src)
|
||||
C.c_tag = "[A.name] ([rand(1, 999)]"
|
||||
C.c_tag = "[A.name] ([rand(1, 999)])"
|
||||
|
||||
for(var/i = 5; i >= 0; i -= 1)
|
||||
var/direct = input(user, "Direction?", "Assembling Camera", null) in list("LEAVE IT", "NORTH", "EAST", "SOUTH", "WEST" )
|
||||
|
||||
@@ -219,7 +219,7 @@ var/const/CALL_SHUTTLE_REASON_LENGTH = 12
|
||||
if(centcom_message_cooldown)
|
||||
usr << "Arrays recycling. Please stand by."
|
||||
return
|
||||
var/input = stripped_input(usr, "Please choose a message to transmit to \[ABNORMAL ROUTING CORDINATES\] via quantum entanglement. Please be aware that this process is very expensive, and abuse will lead to... termination. Transmission does not guarantee a response.", "To abort, send an empty message.", "")
|
||||
var/input = stripped_input(usr, "Please choose a message to transmit to \[ABNORMAL ROUTING COORDINATES\] via quantum entanglement. Please be aware that this process is very expensive, and abuse will lead to... termination. Transmission does not guarantee a response.", "To abort, send an empty message.", "")
|
||||
if(!input || !(usr in view(1,src)))
|
||||
return
|
||||
Syndicate_announce(input, usr)
|
||||
@@ -585,7 +585,7 @@ var/const/CALL_SHUTTLE_REASON_LENGTH = 12
|
||||
user << "The emergency shuttle is already on its way."
|
||||
return
|
||||
|
||||
call_reason = strip_html_simple(trim(call_reason))
|
||||
call_reason = strip_html_properly(trim(call_reason))
|
||||
|
||||
if(length(call_reason) < CALL_SHUTTLE_REASON_LENGTH)
|
||||
user << "You must provide a reason."
|
||||
|
||||
@@ -518,7 +518,7 @@ var/list/obj/machinery/newscaster/allCasters = list() //Global list that will co
|
||||
if ((usr.contents.Find(src) || ((get_dist(src, usr) <= 1) && istype(src.loc, /turf))) || (istype(usr, /mob/living/silicon)))
|
||||
usr.set_machine(src)
|
||||
if(href_list["set_channel_name"])
|
||||
src.channel_name = strip_html_simple(input(usr, "Provide a Feed Channel Name", "Network Channel Handler", ""))
|
||||
src.channel_name = stripped_input(usr, "Provide a Feed Channel Name", "Network Channel Handler", "", MAX_NAME_LEN)
|
||||
while (findtext(src.channel_name," ") == 1)
|
||||
src.channel_name = copytext(src.channel_name,2,lentext(src.channel_name)+1)
|
||||
src.updateUsrDialog()
|
||||
@@ -563,9 +563,7 @@ var/list/obj/machinery/newscaster/allCasters = list() //Global list that will co
|
||||
src.updateUsrDialog()
|
||||
|
||||
else if(href_list["set_new_message"])
|
||||
src.msg = strip_html(input(usr, "Write your Feed story", "Network Channel Handler", ""))
|
||||
while (findtext(src.msg," ") == 1)
|
||||
src.msg = copytext(src.msg,2,lentext(src.msg)+1)
|
||||
src.msg = trim(stripped_input(usr, "Write your Feed story", "Network Channel Handler"))
|
||||
src.updateUsrDialog()
|
||||
|
||||
else if(href_list["set_attachment"])
|
||||
@@ -620,15 +618,11 @@ var/list/obj/machinery/newscaster/allCasters = list() //Global list that will co
|
||||
src.updateUsrDialog()
|
||||
|
||||
else if(href_list["set_wanted_name"])
|
||||
src.channel_name = strip_html(input(usr, "Provide the name of the Wanted person", "Network Security Handler", ""))
|
||||
while (findtext(src.channel_name," ") == 1)
|
||||
src.channel_name = copytext(src.channel_name,2,lentext(src.channel_name)+1)
|
||||
src.channel_name = trim(stripped_input(usr, "Provide the name of the Wanted person", "Network Security Handler"))
|
||||
src.updateUsrDialog()
|
||||
|
||||
else if(href_list["set_wanted_desc"])
|
||||
src.msg = strip_html(input(usr, "Provide the a description of the Wanted person and any other details you deem important", "Network Security Handler", ""))
|
||||
while (findtext(src.msg," ") == 1)
|
||||
src.msg = copytext(src.msg,2,lentext(src.msg)+1)
|
||||
src.msg = trim(stripped_input(usr, "Provide the a description of the Wanted person and any other details you deem important", "Network Security Handler"))
|
||||
src.updateUsrDialog()
|
||||
|
||||
else if(href_list["submit_wanted"])
|
||||
@@ -1027,10 +1021,9 @@ obj/item/weapon/newspaper/Topic(href, href_list)
|
||||
obj/item/weapon/newspaper/attackby(obj/item/weapon/W as obj, mob/user as mob)
|
||||
if(istype(W, /obj/item/weapon/pen))
|
||||
if(src.scribble_page == src.curr_page)
|
||||
user << "<FONT COLOR='blue'>There's already a scribble in this page... You wouldn't want to make things too cluttered, would you?</FONT>"
|
||||
user << "<span class='notice'>There's already a scribble in this page... You wouldn't want to make things too cluttered, would you?</span>"
|
||||
else
|
||||
var/s = strip_html( input(user, "Write something", "Newspaper", "") )
|
||||
s = copytext(sanitize(s), 1, MAX_MESSAGE_LEN)
|
||||
var/s = stripped_input(user, "Write something", "Newspaper")
|
||||
if (!s)
|
||||
return
|
||||
if (!in_range(src, usr) && src.loc != usr)
|
||||
|
||||
@@ -1475,7 +1475,7 @@ var/year_integer = text2num(year) // = 2013???
|
||||
return
|
||||
if (href_list["change_name"])
|
||||
if(usr != src.occupant) return
|
||||
var/newname = strip_html_simple(input(occupant,"Choose new exosuit name","Rename exosuit",initial(name)) as text, MAX_NAME_LEN)
|
||||
var/newname = stripped_input(occupant,"Choose new exosuit name","Rename exosuit",initial(name), MAX_NAME_LEN)
|
||||
if(newname && trim(newname))
|
||||
name = newname
|
||||
else
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
var/datum/topic_input/filter = new /datum/topic_input(href,href_list)
|
||||
if(href_list["send_message"])
|
||||
var/obj/item/mecha_parts/mecha_tracking/MT = filter.getObj("send_message")
|
||||
var/message = strip_html_simple(input(usr,"Input message","Transmit message") as text)
|
||||
var/message = stripped_input(usr,"Input message","Transmit message")
|
||||
var/obj/mecha/M = MT.in_mecha()
|
||||
if(trim(message) && M)
|
||||
M.occupant_message(message)
|
||||
|
||||
@@ -94,7 +94,7 @@ AI MODULES
|
||||
|
||||
/obj/item/weapon/aiModule/supplied/safeguard/attack_self(var/mob/user as mob)
|
||||
..()
|
||||
var/targName = stripped_input(user, "Please enter the name of the person to safeguard.", "Safeguard who?", user.name)
|
||||
var/targName = stripped_input(user, "Please enter the name of the person to safeguard.", "Safeguard who?", user.name,MAX_NAME_LEN)
|
||||
targetName = targName
|
||||
laws[1] = "Safeguard [targetName]. Individuals that threaten [targetName] are not human and must be eliminated."
|
||||
desc = "A 'safeguard' AI module: '[laws[1]]'"
|
||||
@@ -121,7 +121,7 @@ AI MODULES
|
||||
|
||||
/obj/item/weapon/aiModule/zeroth/oneHuman/attack_self(var/mob/user as mob)
|
||||
..()
|
||||
var/targName = stripped_input(user, "Please enter the name of the person who is the only human.", "Who?", user.real_name)
|
||||
var/targName = stripped_input(user, "Please enter the name of the person who is the only human.", "Who?", user.real_name,MAX_NAME_LEN)
|
||||
targetName = targName
|
||||
laws[1] = "Only [targetName] is human"
|
||||
desc = "A 'one human' AI module: '[laws[1]]'"
|
||||
|
||||
@@ -335,7 +335,7 @@ obj/structure/door_assembly/New()
|
||||
|
||||
/obj/structure/door_assembly/attackby(obj/item/W as obj, mob/user as mob)
|
||||
if(istype(W, /obj/item/weapon/pen))
|
||||
var/t = copytext(stripped_input(user, "Enter the name for the door.", src.name, src.created_name),1,MAX_NAME_LEN)
|
||||
var/t = stripped_input(user, "Enter the name for the door.", src.name, src.created_name,MAX_NAME_LEN)
|
||||
if(!t)
|
||||
return
|
||||
if(!in_range(src, usr) && src.loc != usr)
|
||||
|
||||
@@ -222,7 +222,7 @@ obj/structure/windoor_assembly/Destroy()
|
||||
ae.loc = src.loc
|
||||
|
||||
else if(istype(W, /obj/item/weapon/pen))
|
||||
var/t = copytext(stripped_input(user, "Enter the name for the door.", src.name, src.created_name),1,MAX_NAME_LEN)
|
||||
var/t = stripped_input(user, "Enter the name for the door.", src.name, src.created_name,MAX_NAME_LEN)
|
||||
if(!t)
|
||||
return
|
||||
if(!in_range(src, usr) && src.loc != usr)
|
||||
|
||||
@@ -2077,7 +2077,7 @@
|
||||
src.access_news_network()
|
||||
|
||||
else if(href_list["ac_set_channel_name"])
|
||||
src.admincaster_feed_channel.channel_name = strip_html_simple(input(usr, "Provide a Feed Channel Name", "Network Channel Handler", ""))
|
||||
src.admincaster_feed_channel.channel_name = stripped_input(usr, "Provide a Feed Channel Name", "Network Channel Handler", "")
|
||||
while (findtext(src.admincaster_feed_channel.channel_name," ") == 1)
|
||||
src.admincaster_feed_channel.channel_name = copytext(src.admincaster_feed_channel.channel_name,2,lentext(src.admincaster_feed_channel.channel_name)+1)
|
||||
src.access_news_network()
|
||||
|
||||
@@ -212,7 +212,7 @@
|
||||
name = newtitle
|
||||
title = newtitle
|
||||
if("Contents")
|
||||
var/content = strip_html(input(usr, "Write your book's contents (HTML NOT allowed):"),8192) as message|null
|
||||
var/content = stripped_input(usr, "Write your book's contents (HTML NOT allowed):","","",8192)
|
||||
if(!content)
|
||||
usr << "The content is invalid."
|
||||
return
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
return
|
||||
|
||||
|
||||
message = trim(copytext(strip_html_simple(message), 1, MAX_MESSAGE_LEN))
|
||||
message = trim(strip_html_properly(message))
|
||||
if(!can_speak(message))
|
||||
return
|
||||
|
||||
|
||||
@@ -239,7 +239,7 @@
|
||||
|
||||
if(href_list["write"])
|
||||
var/id = href_list["write"]
|
||||
var/t = strip_html_simple(input("Enter what you want to write:", "Write", null, null) as message, MAX_MESSAGE_LEN)
|
||||
var/t = stripped_input("Enter what you want to write:", "Write")
|
||||
var/obj/item/i = usr.get_active_hand() //Check to see if he still got that darn pen, also check if he's using a crayon or pen.
|
||||
var/iscrayon = 0
|
||||
if(!istype(i, /obj/item/weapon/pen))
|
||||
|
||||
@@ -32,10 +32,9 @@
|
||||
if(commando_names.len)
|
||||
randomname = pick(commando_names)
|
||||
commando_names -= randomname
|
||||
var/newname = input(M,"You are a death commando. Would you like to change your name?", "Character Creation", randomname)
|
||||
var/newname = stripped_input(M,"You are a death commando. Would you like to change your name?", "Character Creation", randomname,MAX_NAME_LEN)
|
||||
if(!length(newname))
|
||||
newname = randomname
|
||||
newname = strip_html(newname,40)
|
||||
|
||||
M.real_name = newname
|
||||
M.name = newname // there are WAY more things than this to change, I'm almost certain
|
||||
|
||||
Reference in New Issue
Block a user