Skip to content

Commit 650b88b

Browse files
committed
xmlinputfactory-dtd-enabled-scala
1 parent ac0edaa commit 650b88b

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
id: xmlinputfactory-dtd-enabled-scala
2+
language: scala
3+
severity: warning
4+
message: >-
5+
XMLInputFactory being instantiated without calling the setProperty
6+
functions that are generally used for disabling entity processing. User
7+
controlled data in XML Document builder can result in XML Internal Entity
8+
Processing vulnerabilities like the disclosure of confidential data,
9+
denial of service, Server Side Request Forgery (SSRF), port scanning. Make
10+
sure to disable entity processing functionality.
11+
note: >-
12+
[CWE-611] Improper Restriction of XML External Entity.
13+
[REFERENCES]
14+
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration
15+
rule:
16+
any:
17+
- pattern: XMLInputFactory.newFactory($$$)
18+
- pattern: XMLInputFactory.newInstance($$$)
19+
- pattern: new XMLInputFactory($$$)
20+
precedes:
21+
not:
22+
pattern: $XMLFACTORY.setProperty($MODE, false)
23+
constraints:
24+
MODE:
25+
regex: 'javax.xml.stream.isSupportingExternalEntities'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
id: xmlinputfactory-dtd-enabled-scala
2+
snapshots:
3+
? |-
4+
val factory = XMLInputFactory.newFactory()
5+
val fileReader = new FileReader(file)
6+
val fileReader = new FileReader(file)
7+
: labels:
8+
- source: XMLInputFactory.newFactory()
9+
style: primary
10+
start: 14
11+
end: 42
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
id: xmlinputfactory-dtd-enabled-scala
2+
valid:
3+
- |
4+
val factory = XMLInputFactory.newInstance
5+
factory.setProperty("javax.xml.stream.isSupportingExternalEntities", false)
6+
val fileReader = new FileReader(file)
7+
invalid:
8+
- |
9+
val factory = XMLInputFactory.newFactory()
10+
val fileReader = new FileReader(file)
11+
val fileReader = new FileReader(file)

0 commit comments

Comments
 (0)