<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Message</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16788" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=524104114-27012009><FONT face=Arial color=#0000ff 
size=2>Right.&nbsp; </FONT></SPAN></DIV>
<DIV><SPAN class=524104114-27012009><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=524104114-27012009><FONT face=Arial color=#0000ff size=2>I 
believe that several layers to the onion are good.&nbsp; </FONT></SPAN></DIV>
<DIV><SPAN class=524104114-27012009><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=524104114-27012009><FONT face=Arial color=#0000ff size=2>In 
other words, I wouldn't have my Web application logging into my db as the admin 
user even if I was using validation on my input.</FONT></SPAN></DIV>
<DIV><SPAN class=524104114-27012009><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=524104114-27012009><FONT face=Arial color=#0000ff 
size=2>David.</FONT></SPAN></DIV>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px">
  <DIV></DIV>
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT 
  face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> 
  mapserver-users-bounces@lists.osgeo.org 
  [mailto:mapserver-users-bounces@lists.osgeo.org] <B>On Behalf Of 
  </B>umn-ms@hydrotec.de<BR><B>Sent:</B> Tuesday, January 27, 2009 2:14 
  AM<BR><B>To:</B> MapServer<BR><B>Cc:</B> Steve Lime; David 
  Fawcett<BR><B>Subject:</B> RE: [mapserver-users] Dynamin SQL with mapserver 
  CGI?<BR><BR></FONT></DIV><BR><FONT face=sans-serif size=2>I think validation 
  patterns are a real solution to the problem and minimizing access-priviliges 
  is not.</FONT> <BR><BR><FONT face=sans-serif size=2>When filter with 
  URL-substitution is used without validation patterns, one relies on the 
  security-system of postgres. </FONT><BR><FONT face=sans-serif size=2>This is 
  acceptable in most intranets but hazardous in the internet.</FONT> <BR><FONT 
  face=sans-serif size=2>Look for example at 
  http://www.postgresql.org/support/security.html what can be done with even a 
  minimal-postgres-login</FONT> <BR><BR><FONT face=sans-serif size=2>Ciao</FONT> 
  <BR><FONT face=sans-serif size=2>Benedikt</FONT> <BR><BR><FONT face=sans-serif 
  size=2>Extract of the http://www.postgresql.org/support/security.html</FONT> 
  <BR><FONT face=sans-serif size=2>* </FONT><FONT size=3>Three vulnearbilities 
  in the regular expression handling libraries can be exploited to cause a 
  backend crash, infinite loops or memory exhaustion. This vulnearbility can be 
  exploited through frontend applications that allow unfiltered regular 
  expressions to be passed in queries. </FONT><BR><FONT face=sans-serif size=2>* 
  </FONT><FONT size=3>A bug in the handling of SET ROLE allows escalation of 
  privileges to any other database user, including superuser. A valid login is 
  required to exploit this vulnerability </FONT><BR><FONT face=sans-serif 
  size=2>* </FONT><FONT size=3>Calling COALESCE() with two NULL parameters would 
  cause the current backend to crash, causing a denial of service. A valid login 
  is required to exploit this vulnerability. </FONT><BR><FONT face=sans-serif 
  size=2>* </FONT><FONT size=3>Public EXECUTE access is given to certain 
  character conversion functions that are not designed to be safe against 
  malicious arguments. This can cause at least a denial of service. A valid 
  login is required to exploit this vulnerability </FONT><BR><BR><BR><TT><FONT 
  size=2>"Steve Lime" &lt;Steve.Lime@dnr.state.mn.us&gt; schrieb am 26.01.2009 
  21:29:52:<BR><BR>&gt; In addition, one can and should apply validation 
  patterns to variables<BR>&gt; used in SQL. That way MapServer<BR>&gt; can test 
  the input data before handing off to PostGIS or whatever.<BR>&gt; <BR>&gt; 
  These patterns are set in LAYER metadata. For example:<BR>&gt; <BR>&gt; 
  LAYER<BR>&gt; &nbsp; ...<BR>&gt; &nbsp; DATA"'the_geom FROM (SELECT the_geom 
  FROM my_table WHERE ID = '%id%')<BR>&gt; as foo USING UNIQUE OID" 
  &nbsp;<BR>&gt; &nbsp; METADATA<BR>&gt; &nbsp; &nbsp; id_validation_pattern 
  '^[0-9]{3}$'<BR>&gt; &nbsp; END<BR>&gt; END<BR>&gt; <BR>&gt; This tells the 
  CGI to test the request parameter against the regex<BR>&gt; '^[1-9]{3}$'. The 
  regex says that the value<BR>&gt; of the id variable must be an number exactly 
  3 digits long with no<BR>&gt; zeros. Any attempt to send a value other<BR>&gt; 
  than that will generate an error message. The CGI code does not force<BR>&gt; 
  the use of validation.<BR>&gt; <BR>&gt; Validation like this will be further 
  expanded in 5.4 with the addition<BR>&gt; of a new validation object. So you'd 
  see <BR>&gt; something like:<BR>&gt; <BR>&gt; LAYER<BR>&gt; &nbsp; ...<BR>&gt; 
  &nbsp; VALIDATION<BR>&gt; &nbsp; &nbsp; 'id' &nbsp;'^[0-9]{3}$<BR>&gt; &nbsp; 
  END<BR>&gt; END<BR>&gt; <BR>&gt; Steve<BR>&gt; <BR>&gt; &gt;&gt;&gt; On 
  1/26/2009 at 8:47 AM, in message<BR>&gt; 
  &lt;6246727221874A4FB8D3F9BBC37D9BD5056DA174@s-sp22.pca.state.mn.us&gt;,<BR>&gt; 
  "Fawcett,<BR>&gt; David" &lt;David.Fawcett@state.mn.us&gt; wrote:<BR>&gt; &gt; 
  Of course, part of security is also having your application hit your<BR>&gt; 
  database <BR>&gt; &gt; as a user that only has the rights that it needs. 
  &nbsp;If your user only<BR>&gt; has <BR>&gt; &gt; select rights on only the 
  data that you want to expose, that should<BR>&gt; help <BR>&gt; &gt; limit 
  some of these issues.<BR>&gt; &gt; <BR>&gt; &gt; &nbsp; &nbsp;-----Original 
  Message-----<BR>&gt; &gt; &nbsp; &nbsp;From: 
  mapserver-users-bounces@lists.osgeo.org <BR>&gt; &gt; 
  [mailto:mapserver-users-bounces@lists.osgeo.org] On Behalf Of <BR>&gt; &gt; 
  umn-ms@hydrotec.de <BR>&gt; &gt; &nbsp; &nbsp;Sent: Monday, January 26, 2009 
  4:43 AM<BR>&gt; &gt; &nbsp; &nbsp;To: MapServer<BR>&gt; &gt; &nbsp; 
  &nbsp;Subject: Re: [mapserver-users] Dynamin SQL with mapserver CGI?<BR>&gt; 
  &gt; &nbsp; &nbsp;<BR>&gt; &gt; &nbsp; &nbsp;<BR>&gt; &gt; <BR>&gt; &gt; 
  &nbsp; &nbsp;&gt; Not any great hazard, I believe, ... <BR>&gt; &gt; &nbsp; 
  &nbsp;<BR>&gt; &gt; &nbsp; &nbsp;Mmh. I'd be cautious. <BR>&gt; &gt; &nbsp; 
  &nbsp;<BR>&gt; &gt; &nbsp; &nbsp;Example: <BR>&gt; &gt; &nbsp; &nbsp;* 
  Mapfile: <BR>&gt; &gt; &nbsp; &nbsp; &nbsp; DATA "the_geom from 
  buildings"<BR>&gt; &gt; &nbsp; &nbsp;<BR>&gt; &gt; &nbsp; &nbsp;* Set Filter 
  via URL to this: <BR>&gt; &gt; &nbsp; &nbsp; &nbsp;1=1);DELETE FROM 
  OTHERTABLE; DECLARE X BINARY CURSOR FOR<BR>&gt; SELECT * from <BR>&gt; &gt; 
  buildings WHERE (1=1 <BR>&gt; &gt; &nbsp; &nbsp;<BR>&gt; &gt; &nbsp; &nbsp;I 
  think Mapserver will create the following statements: (I've<BR>&gt; added 
  <BR>&gt; &gt; newlines) <BR>&gt; &gt; &nbsp; &nbsp;DECLARE mycursor BINARY 
  CURSOR FOR SELECT the_geom from<BR>&gt; buildings WHERE <BR>&gt; &gt; (1=1); 
  <BR>&gt; &gt; &nbsp; &nbsp;DELETE FROM OTHERTABLE; <BR>&gt; &gt; &nbsp; 
  &nbsp;DECLARE X BINARY CURSOR FOR SELECT * from buildings WHERE (1=1)<BR>&gt; 
  and (%s &amp;&amp; <BR>&gt; &gt; setSRID( ...) ) <BR>&gt; &gt; &nbsp; 
  &nbsp;<BR>&gt; &gt; &nbsp; &nbsp;Mapserver calls PQExec with these statements. 
  PQExec will<BR>&gt; execute every <BR>&gt; &gt; statement and will return 
  <BR>&gt; &gt; &nbsp; &nbsp;the results of the last one. <BR>&gt; &gt; &nbsp; 
  &nbsp;<BR>&gt; &gt; &nbsp; &nbsp;Bye <BR>&gt; &gt; &nbsp; &nbsp;Benedikt Rothe 
  <BR>&gt; &gt; &nbsp; &nbsp;<BR>&gt; &gt; &nbsp; &nbsp;<BR>&gt; &gt; &nbsp; 
  &nbsp;"Rahkonen Jukka" &lt;Jukka.Rahkonen@mmmtike.fi&gt; schrieb am<BR>&gt; 
  26.01.2009 09:34:31:<BR>&gt; &gt; &nbsp; &nbsp;<BR>&gt; &gt; &nbsp; &nbsp;&gt; 
  Hi, <BR>&gt; &gt; &nbsp; &nbsp;&gt; &nbsp; <BR>&gt; &gt; &nbsp; &nbsp;&gt; Not 
  any great hazard, I believe, if it means that user can<BR>&gt; normally 
  <BR>&gt; &gt; &nbsp; &nbsp;&gt; get all the features, but only a subset when 
  filter is set. <BR>&gt; It is <BR>&gt; &gt; &nbsp; &nbsp;&gt; different case 
  if DATA clause is manipulated, and therefore<BR>&gt; that <BR>&gt; &gt; &nbsp; 
  &nbsp;&gt; must be connected to DATAPATTERN. <BR>&gt; &gt; &nbsp; &nbsp;&gt; 
  &nbsp; <BR>&gt; &gt; &nbsp; &nbsp;&gt; -Jukka Rahkonen- <BR>&gt; &gt; &nbsp; 
  &nbsp;&gt; <BR>&gt; &gt; &nbsp; &nbsp;&gt; Lähettäjä: 
  mapserver-users-bounces@lists.osgeo.org [mailto:<BR>&gt; &gt; &nbsp; 
  &nbsp;&gt; mapserver-users-bounces@lists.osgeo.org] Puolesta<BR>&gt; 
  umn-ms@hydrotec.de <BR>&gt; &gt; &nbsp; &nbsp;&gt; Lähetetty: 26. tammikuuta 
  2009 10:03<BR>&gt; &gt; &nbsp; &nbsp;&gt; Vastaanottaja: MapServer<BR>&gt; 
  &gt; &nbsp; &nbsp;&gt; Aihe: Re: [mapserver-users] Dynamin SQL with mapserver 
  CGI?<BR>&gt; &gt; &nbsp; &nbsp;<BR>&gt; &gt; &nbsp; &nbsp;&gt; <BR>&gt; &gt; 
  &nbsp; &nbsp;&gt; Hi <BR>&gt; &gt; &nbsp; &nbsp;&gt; <BR>&gt; &gt; &nbsp; 
  &nbsp;&gt; &gt; You can use a replaceable parameter in the FILTER clause 
  if<BR>&gt; all you ... <BR>&gt; &gt; &nbsp; &nbsp;&gt; This introduces the 
  hazard of SQL-Injection, doesn't it? <BR>&gt; &gt; &nbsp; &nbsp;&gt; <BR>&gt; 
  &gt; &nbsp; &nbsp;&gt; Bye <BR>&gt; &gt; &nbsp; &nbsp;&gt; Benedikt Rothe 
  <BR>&gt; &gt; &nbsp; &nbsp;&gt; <BR>&gt; &gt; &nbsp; &nbsp;&gt; 
  mapserver-users-bounces@lists.osgeo.org schrieb am 24.01.2009<BR>&gt; 
  14:04:42:<BR>&gt; &gt; &nbsp; &nbsp;&gt; <BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; 
  On Sat, Jan 24, 2009 at 3:18 AM, Saka Royban<BR>&gt; &lt;srph124@yahoo.com&gt; 
  wrote:<BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; &gt; Hi all<BR>&gt; &gt; &nbsp; 
  &nbsp;&gt; &gt; &gt; I'm looking for a way to change SQL dynamically via 
  URL<BR>&gt; parameters. it<BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; &gt; sounds 
  from doc that changing DATA element in map file is<BR>&gt; impossible. 
  Is<BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; &gt; there any other way?<BR>&gt; &gt; 
  &nbsp; &nbsp;&gt; &gt; <BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; You can use a 
  replaceable parameter in the FILTER clause if<BR>&gt; all you<BR>&gt; &gt; 
  &nbsp; &nbsp;&gt; &gt; want to do is alter the WHERE clause. So for 
  example:<BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; &nbsp; &nbsp;FILTER 
  "%criteria%"<BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; and<BR>&gt; &gt; &nbsp; 
  &nbsp;&gt; &gt; &nbsp; criteria=id='value'<BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; 
  would work with a database like Postgres.<BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; 
  <BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; When working with a database you put the 
  whole SQL WHERE<BR>&gt; clause in the<BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; 
  FILTER, whereas with shapefiles or ORG data sources you use<BR>&gt; 
  the<BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; FILTERITEM and FILTER.<BR>&gt; &gt; 
  &nbsp; &nbsp;&gt; &gt; <BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; -- <BR>&gt; &gt; 
  &nbsp; &nbsp;&gt; &gt; Richard Greenwood<BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; 
  richard.greenwood@gmail.com <BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; 
  www.greenwoodmap.com <BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; 
  _______________________________________________<BR>&gt; &gt; &nbsp; &nbsp;&gt; 
  &gt; mapserver-users mailing list<BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; 
  mapserver-users@lists.osgeo.org <BR>&gt; &gt; &nbsp; &nbsp;&gt; &gt; 
  http://lists.osgeo.org/mailman/listinfo/mapserver-users<BR></BLOCKQUOTE></FONT></TT></BODY></HTML>