perl - Remove unsafe HTTP characters from a string -
i have send bunch of string variables payloads in http post message using perl.
i want remove "unsafe" characters, such < > “ ‘ % ; ) ( & + string variable.
i know can use regex pattern find , replace each of these characters, wondering if there's existing perl library that.
for example, found apache::util
my $esc = apache::util::escape_uri($uri); can use apache::util::escape this? or there better way?
edit 1: have mentioned unsafe, mean characters < > “ ‘ % ; ) ( & + can used in sql-injection. don't know how describe problem better.
edit 2: here's code working on -it's embedded perl code:
$cgi = cgi->new(); $param1 = $cgi->param('param1'); $param2 = $cgi->param('param2'); $param3 = $cgi->param('param3'); # want remove unsafe characters (< > “ ‘ % ; ) ( & +) $param1, $param2 , $param3 # q is, use apache::util::escape_uri; if that's removing unsafe chars uri? # or use uri::escape 'uri_escape';? $script = <<__html__; <script> api.call ({ 'parama': '$param1', 'paramb': '$param2', 'paramc': '$param3' }); </script> __html__ edit 3: if else has same question, ended writing perl function looks characters such "(", "{", "$", ";", etc , removes them provided string parameter.
list of characters escaping are: ";", "(", ")", "[", "]", "{", "}", "~", "`", "/", "<", ">", "&", "|", "'", "\"", "\\"
obviously, there's room exclusions well.
there no general definition of unsafe characters, falls determine whether of answers fulfill requirement
looking @ the source of apache::util unpleasant things own name space, , wouldn't trust it. intended used component of mod_perl, , shouldn't accessed in isolation
i think canonical way of escaping http uris use uri::escape module
use uri::escape 'uri_escape'; you must provide data , code more this
Comments
Post a Comment