Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Use CGI to run a Perl script via web server (updated)

by haukex (Archbishop)
on May 25, 2017 at 14:15 UTC ( [id://1191217]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Use CGI to run a Perl script via web server
in thread Use CGI to run a Perl script via web server

There is no security risk as this Link will only be used from within a different application.

Sorry, but those are famous last words. Getting security right is really hard. At the very least, you need to use the LIST form of system, i.e. system("cqperl","NewLdapUser.pl",$sso,$firstName,$lastName,$email);, and even better, since you're already using IPC::System::Simple, be explicit by using its systemx instead of system function. <update2> Plus, what hippo said, plus some kind of authentication for this script, and so on. </update2>

... creates a user account in another application (using system call). Reason is mentioned in the script comments.

I admit I don't know cqperl (ClearQuest Perl?), but I'm not entirely convinced that whatever the Perl script NewLdapUser.pl is doing could not be done by your CGI script, especially given that your script is already making use of Net::LDAP.

$sso == ""

This is not doing what you want, as Perl would tell you, that's why you should always Use strict and warnings. Use eq instead and see the Basic debugging checklist.

All I am looking for is to find out a way to parse the value from $sso = shift to just $sso using CGI.

I'm not sure I understand the question, are you having trouble with getting the CGI parameters? I don't really see anything immediately wrong with my $sso = $query->param("sso");, have you tried narrowing down your script to only that part and attempting to debug it (using the links previously provided)?

Update: Your code also seems to be potentially vulnerable to a Cross-site scripting (XSS) attack, see also this. Even if not, you should still use CGI's escapeHTML() function.

Replies are listed 'Best First'.
Re^4: Use CGI to run a Perl script via web server (updated)
by suvajit123 (Initiate) on May 25, 2017 at 20:08 UTC

    Surely I will look into the security aspect, but at this moment the code fails because 'use CGI' cannot be clubbed with other things like 'use Net::LDAP' or 'IPC:System::Simple'. If I disable them I could execute it.

    But disabling them will take away the entire purpose of the script i.e. automated user management.

    #!/usr/bin/perl use strict; use CGI; use CGI::Carp; #create CGI query object to get the SSO from URL my $query = CGI->new; my $sso = $query->param("sso"); $sso = shift; print "Content-type:text/html\r\n\r\n"; print "<html>"; print "<head>"; print "<title>Application Management Sysyem</title>"; print "</head>"; if($sso eq "") { print "<h1>\n\nERROR: SSO is EMPTY!</h1>\n\n"; } else { use Proc::Background; print "<body>"; print "<h2>You have entered $sso</h2>"; print "</body>"; print "</html>"; }

    I really appreciate help.

      my $sso = $query->param("sso"); $sso = shift;

      These two lines in sequence don't make sense.

      Either you read $sso from a CGI parameter, or you read it from the command line.

      If you read it from a CGI parameter, you will be setting it to undef right afterwards with the above code. That doesn't make sense.

      the code fails

      What does that mean?

        The code fails with 500: Internal Server Error. But if I don't use IPC::System::Simple and Net::LDAP, then it works fine.

        About reading the variable $sso, it is reading from CGI but unless used a shift flag it cannot be parsed into the Perl api further. I hope this could have been done by METHODS "GET" or "POST" as well, but unfortunately I am not sure how to use those in this scenario.

        As always, thanks for the insights.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-18 16:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found