Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Collapsing smaller scripts into a larger one, request for comment

by duelafn (Parson)
on May 29, 2020 at 22:56 UTC ( [id://11117482]=note: print w/replies, xml ) Need Help??


in reply to Collapsing smaller scripts into a larger one, request for comment

Be careful with opening files from CGI parameters. collection=../../../../../../../home/aleena/passwords would reveal a bit more than you intended ("passwords.txt" in your home directory).

Good Day,
    Dean

Replies are listed 'Best First'.
Re^2: Collapsing smaller scripts into a larger one, request for comment
by Lady_Aleena (Priest) on May 30, 2020 at 00:12 UTC

    Thank you for bringing this to my attention. If I ever store passwords somewhere, I will make sure to keep them out of the $collections_dir. I would probably put them in some deep dark corner of my directory structure with a name that does not look anything like the word 'password' and use something more secure than a plain text file.

    I could also add / and . to the encode entities to make sure that the string that the cgi param returns will not recurse. Adding those would make your string return the following.

    ../../../../.. +/../../home/aleena/passwords

    I will give that serious thought. Again, thank you.

    Update: Forward slashes will be html encoded.

    my $collection = $cgi->param('collection') ? encode_entities($cg +i->param('collection'),'/<>"') : undef;

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.8.8 on web host.

    Version control is a non-issue, I do not use it.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena

      If it were me, I'd use the list of valid collections that you already have (assuming I understand your data correctly). Something like:

      # Note: Still has underscsores: my @collections = map { $_ =~ s/\.txt//; $_ } grep {/^\p{uppercase}/} @collections_list; # $collection guaranteed to match one of your file names. my $collection_raw = $cgi->param('collection'); my ($collection) = grep { $_ eq $collection_raw } @collections; $collection //= 'Deafult'; # If your file names might have <>", you can still do this: $collection = encode_entities($collection); # Without underscores my @collection_labels = map { $_ =~ s/_/ /g; $_ } @collections;

      Generally, it is safest to do something like this before using $collections for anything.

      Good Day,
          Dean

        I should have had that in already! Thank you for the reminder. I did it just a tad differently, but the same result.

        My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.8.8 on web host.

        Version control is a non-issue, I do not use it.

        No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
        Lady Aleena

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11117482]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-03-29 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found