Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions pycsw/ogc/csw/csw2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1639,11 +1639,17 @@ def parse_postdata(self, postdata):
# csw:Insert|csw:Update (with single child) XML document.
# Only validate non csw:Transaction XML

if doc.find('.//%s' % util.nspath_eval('csw:Insert',
self.parent.context.namespaces)) is None and \
len(doc.xpath('//csw:Update/child::*',
namespaces=self.parent.context.namespaces)) == 0:
if (doc.find('.//%s' % util.nspath_eval('csw:Insert', self.parent.context.namespaces)) is None and \
len(doc.xpath('//csw:Update/child::*', namespaces=self.parent.context.namespaces)) == 0):
validate_ = True
elif len(doc.xpath('//csw:RecordProperty', namespaces=self.parent.context.namespaces)) == 1:
validate_ = True
elif len(doc.xpath('//csw:Constraint', namespaces=self.parent.context.namespaces)) == 1:
validate_ = True
else:
validate_ = False

if validate_:
LOGGER.info('Validating %s', postdata)
schema = etree.XMLSchema(file=schema)
parser = etree.XMLParser(schema=schema, resolve_entities=False)
Expand All @@ -1653,8 +1659,10 @@ def parse_postdata(self, postdata):
else: # validate the request normally
doc = etree.fromstring(postdata, parser)
LOGGER.debug('Request is valid XML.')

else: # parse Transaction without validation
doc = etree.fromstring(postdata, self.parent.context.parser)

except Exception as err:
errortext = \
'Exception: the document is not valid.\nError: %s' % str(err)
Expand Down
22 changes: 15 additions & 7 deletions pycsw/ogc/csw/csw3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1702,16 +1702,22 @@ def parse_postdata(self, postdata):
schema = os.path.join(self.parent.config['server'].get('home'),
'core', 'schemas', 'ogc', 'cat', 'csw', '3.0', xsd_filename)

try:
try:
# it is virtually impossible to validate a csw:Transaction
# csw:Insert|csw:Update (with single child) XML document.
# Only validate non csw:Transaction XML

if doc.find('.//%s' % util.nspath_eval('csw30:Insert',
self.parent.context.namespaces)) is None and \
len(doc.xpath('//csw30:Update/child::*',
namespaces=self.parent.context.namespaces)) == 0:
if (doc.find('.//%s' % util.nspath_eval('csw30:Insert', self.parent.context.namespaces)) is None and \
len(doc.xpath('//csw30:Update/child::*', namespaces=self.parent.context.namespaces)) == 0):
validate_ = True
elif len(doc.xpath('//csw30:RecordProperty', namespaces=self.parent.context.namespaces)) == 1:
validate_ = True
elif len(doc.xpath('//csw30:Constraint', namespaces=self.parent.context.namespaces)) == 1:
validate_ = True
else:
validate_ = False

if validate_:
LOGGER.info('Validating %s', postdata)
schema = etree.XMLSchema(file=schema)
parser = etree.XMLParser(schema=schema, resolve_entities=False)
Expand All @@ -1720,10 +1726,12 @@ def parse_postdata(self, postdata):
doc = etree.fromstring(etree.tostring(doc), parser)
else: # validate the request normally
doc = etree.fromstring(postdata, parser)
LOGGER.debug('Request is valid XML')
LOGGER.debug('Request is valid XML.')

else: # parse Transaction without validation
doc = etree.fromstring(postdata, self.parent.context.parser)
except Exception as err:

except Exception as err:
errortext = \
'Exception: the document is not valid.\nError: %s' % str(err)
LOGGER.exception(errortext)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- PYCSW_VERSION -->
<ows:ExceptionReport xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gml="http://www.opengis.net/gml" xmlns:gml32="http://www.opengis.net/gml/3.2" xmlns:ows="http://www.opengis.net/ows" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2.0" language="en-US" xsi:schemaLocation="http://www.opengis.net/ows http://schemas.opengis.net/ows/1.0.0/owsExceptionReport.xsd">
<ows:Exception exceptionCode="NoApplicableCode" locator="service">
<ows:ExceptionText>Exception: the document is not valid.
Error: Element '{http://www.opengis.net/gml}pos': ')','dwithin','1')/**/OR/**/(1=1)/**/--' is not a valid value of the atomic type 'xs:double'. (&lt;string&gt;, line 0)</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</csw:RecordProperty>
<csw:Constraint version="1.1.0">
<ogc:Filter>
<ogc:PropertyIsLike wildChar="%" singleChar="." escapeChar="\">
<ogc:PropertyIsLike wildCard="%" singleChar="." escapeChar="\">
<ogc:PropertyName>dct:abstract</ogc:PropertyName>
<ogc:Literal>NCEP%</ogc:Literal>
</ogc:PropertyIsLike>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<csw:Transaction xmlns:ogc="http://www.opengis.net/ogc" xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:gml="http://www.opengis.net/gml" service="CSW" version="2.0.2">
<csw:Update>
<csw:RecordProperty>
<csw:Name>apiso:Title</csw:Name>
<csw:Value>sqli-noop-update</csw:Value>
</csw:RecordProperty>
<csw:Constraint version="1.1.0">
<ogc:Filter>
<ogc:DWithin>
<ogc:PropertyName>ows:BoundingBox</ogc:PropertyName>
<gml:Point>
<gml:pos>)','dwithin','1')/**/OR/**/(1=1)/**/-- 1</gml:pos>
</gml:Point>
<ogc:Distance units="m">1</ogc:Distance>
</ogc:DWithin>
</ogc:Filter>
</csw:Constraint>
</csw:Update>
</csw:Transaction>
Loading