cleaning/sanitizing xpath attributes
i need boldly make an xpath query an component attribute, where charge value presumption user. i'm capricious cleaning sanitizing value hinder xpath homogeneous sql injection attack. instance (in php):
<?php
function xpathquery($attr) {
$xml = simplexml_load_file('example.xml');
relapse $xml->xpath("//myelement[@content='{$attr}']");
}
xpathquery('this should work fine');
# //myelement[@content='this should work fine']
xpathquery('as should "this"');
# //myelement[@content='as should "this"']
xpathquery('this\'ll means problems');
# //myelement[@content='this'll means problems']
xpathquery('\']/../privateelement[@content=\'private data');
# //myelement[@content='']/../privateelement[@content='private data']
the final sole revealing sql injection attacks yore.
now, i know fact there attributes containing unparalleled quotes attributes containing double quotes. given presumption an justification function, ideal proceed sanitize quarrel these?
Comments
Post a Comment