Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 12cbdcd

Browse files
committed
Python: Model lxml.etree.XMLID
1 parent 6774085 commit 12cbdcd

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

python/ql/lib/semmle/python/frameworks/Lxml.qll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,15 @@ private module Lxml {
221221
* - `lxml.etree.fromstring`
222222
* - `lxml.etree.fromstringlist`
223223
* - `lxml.etree.XML`
224+
* - `lxml.etree.XMLID`
224225
* - `lxml.etree.parse`
225226
* - `lxml.etree.parseid`
226227
*
227228
* See
228229
* - https://lxml.de/apidoc/lxml.etree.html?highlight=parseids#lxml.etree.fromstring
229230
* - https://lxml.de/apidoc/lxml.etree.html?highlight=parseids#lxml.etree.fromstringlist
230231
* - https://lxml.de/apidoc/lxml.etree.html?highlight=parseids#lxml.etree.XML
232+
* - https://lxml.de/apidoc/lxml.etree.html?highlight=parseids#lxml.etree.XMLID
231233
* - https://lxml.de/apidoc/lxml.etree.html?highlight=parseids#lxml.etree.parse
232234
* - https://lxml.de/apidoc/lxml.etree.html?highlight=parseids#lxml.etree.parseid
233235
*/
@@ -236,14 +238,14 @@ private module Lxml {
236238
this =
237239
API::moduleImport("lxml")
238240
.getMember("etree")
239-
.getMember(["fromstring", "fromstringlist", "XML", "parse", "parseid"])
241+
.getMember(["fromstring", "fromstringlist", "XML", "XMLID", "parse", "parseid"])
240242
.getACall()
241243
}
242244

243245
override DataFlow::Node getAnInput() {
244246
result in [
245247
this.getArg(0),
246-
// fromstring / XML
248+
// fromstring / XML / XMLID
247249
this.getArgByName("text"),
248250
// fromstringlist
249251
this.getArgByName("strings"),
@@ -264,7 +266,7 @@ private module Lxml {
264266
override predicate mayExecuteInput() { none() }
265267

266268
override DataFlow::Node getOutput() {
267-
// Note: for `parseid` the result of the call is a tuple with `(root, dict)`, so
269+
// Note: for `parseid`/XMLID the result of the call is a tuple with `(root, dict)`, so
268270
// maybe we should not just say that the entire tuple is the decoding output... my
269271
// gut feeling is that THIS instance doesn't matter too much, but that it would be
270272
// nice to be able to do this in general. (this is a problem for both `lxml.etree`

python/ql/test/library-tests/frameworks/lxml/parsing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
lxml.etree.XML(x) # $ decodeFormat=XML decodeInput=x xmlVuln='XXE' decodeOutput=lxml.etree.XML(..)
1414
lxml.etree.XML(text=x) # $ decodeFormat=XML decodeInput=x xmlVuln='XXE' decodeOutput=lxml.etree.XML(..)
1515

16+
lxml.etree.XMLID(x) # $ decodeFormat=XML decodeInput=x xmlVuln='XXE' decodeOutput=lxml.etree.XMLID(..)
17+
lxml.etree.XMLID(text=x) # $ decodeFormat=XML decodeInput=x xmlVuln='XXE' decodeOutput=lxml.etree.XMLID(..)
18+
1619
lxml.etree.parse(StringIO(x)) # $ decodeFormat=XML decodeInput=StringIO(..) xmlVuln='XXE' decodeOutput=lxml.etree.parse(..)
1720
lxml.etree.parse(source=StringIO(x)) # $ decodeFormat=XML decodeInput=StringIO(..) xmlVuln='XXE' decodeOutput=lxml.etree.parse(..)
1821

0 commit comments

Comments
 (0)