[mapserver-dev] Database Variable Binding, Revisised w/ RFC

Dan Little danlittle at yahoo.com
Wed Feb 3 11:59:51 EST 2010


I brought this up a few months ago and the conclusion was "write an RFC."  

I've made an attempt to write one and I do have some client funding to implement this for Oracle and for PostGIS.  In fact, it could even be implemented by the end of the code sprint if there was enough interest / votes.


      
-------------- next part --------------

*******************************************************
RFC : Add Variable Binding to Database Connection Types
*******************************************************

:Author: Dan "Ducky" Little
:Contact: danlittle at yahoo.com

Purpose
=======

Both of the major databases used for spatial data storage with MapServer, PostgreSQL and Oracle, offer the ability to "bind" variables in SQL statements.  The reason they provide variable binding is to prevent needing to resolve data-type issues in the SQL and it prevent SQL injection.  Various MapServer applications take untrusted user input from the CGI request and insert it into an SQL statement.  This leaves an open vector for SQL injection.  This also causes some issues as SQL requires properly escaping strings and integers.  Not having to know that ahead of time is useful.

Implementation Details
======================

There is a need to be able to create the key-value pairings for the various databases in a flexible format.  For example, Oracle can use a named bind variable but PostgreSQL only accepts numbers.  These are some examples of variable binding in PostgreSQL and Oralce to illustrate the differences:

PostgreSQL
::

	select count(*) from parcels where city_id = $1

Oracle
::

	select count(*) from parcels where city_id = :city_id

Alternatively, Oracle Could Also be Written
::

	select count(*) from parcels where city_id = :1

This need for flexibility lends itself well to a hash object and it may be appropriate to create a new block in the LAYER object to support it.  For example::

LAYER
	...
	BINDVARS
		'1'  '1345'
	END
	...
END

LAYER
	...
	BINDVARS
		'city_id' '1345'
	END
	...
END


Backward Compatibility Issues
=============================

The implementation would be completely option and not provide any backward compatibility issues.

Documentation
=============

The mainline documentation will need to add the description of the BINDVARS block and its functionality.


More information about the mapserver-dev mailing list