x
Loading
 Loading
Hello, Guest | Login | Register

Processing Web Forms Carefully

CGI applications are often used to search through some database. For example, a catalog might let you look for an item by color, or an on-line dating service might let you pick people by gender, location, age, and interests.

CGI applications are often used to search through some database. For example, a catalog might let you look for an item by color, or an on-line dating service might let you pick people by gender, location, age, and interests.

When the CGI application is in Perl, the database query is frequently performed using the DBI interface. This amazing product, the result of man-years of effort (coordinated by Tim Bunce), allows a Perl program to interact nearly identically with over a few dozen types of databases, including both commercial and open-source databases, and even “non-database” databases like a comma-separated-values (CSV) file. With DBI, the interaction between script and database is primarily in the form of a series of industry-standard SQL statements. And while common, I frequently see the transition from a CGI form element to a SQL query statement as a security risk.

For example, let’s say that the form field firstname accepts an SQL LIKE pattern (e.g., “Tom%”) for the first name of a person I’m searching for in my department. The Perl code to construct an SQL query using firstname as a parameter might look something like Figure One.

Figure One: Typical Perl code to construct an SQL query

 my $department = 123; # determined by some login process my $firstname = param(’firstname’); # from the field my $sql = “SELECT id FROM…

Please log in to view this content.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. Helpful Tools for Software Developers
  2. The Github Hall of Fame
  3. Book'em, Github.
  4. This Week on Github: Stupid Ruby Tricks
  5. A Veritable Scatter Shot!
Follow Linux Magazine
Rackspace