Skip to content

Commit e5f3e76

Browse files
authored
Merge pull request #213 from shivasurya/shiva/xxe-basic-rule
atlas/rule: add basic xxe rule for java xml parser
2 parents e035eb8 + 3519269 commit e5f3e76

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed

docs/src/content/docs/atlas/index.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import Footer from '../../../components/Footer.astro';
3232
<CardGrid>
3333
{/* Java Card */}
3434
<Card title="Java" icon="seti:java">
35-
6 rules for Java applications
35+
7 rules for Java applications
3636
<div>
3737
<a href="/atlas/java" class="view-docs-link">View Rules</a>
3838
</div>

docs/src/content/docs/atlas/java/index.mdx

+33-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ To run these rules against your Java codebase:
2121
codepathfinder ci --project /src/project --ruleset cpf/java
2222
```
2323

24-
#### Rules (4)
24+
#### Rules (7)
2525

2626
<RuleSearch placeholder="Search security rules and patterns..." />
2727

@@ -117,6 +117,38 @@ SSLSocket socket = (SSLSocket) factory.createSocket("example.com", 443);`}
117117
</Card>
118118
</div>
119119

120+
121+
<div class="rule-card" data-severity="high" data-type="security" data-owasp="xml-external-entities">
122+
<Card title="XML External Entity (XXE) Vulnerability" icon="warning">
123+
<div class="description">
124+
**Severity: High** | **OWASP: XML External Entities (XXE)**
125+
Identifies insecure XML parser configurations that could allow XXE attacks, potentially leading to data disclosure, denial of service, or server-side request forgery.
126+
</div>
127+
<div class="code-section">
128+
<CollapsibleCode
129+
code={`
130+
// ❌ Vulnerable: Disabling protection
131+
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
132+
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false);
133+
DocumentBuilder builder = dbf.newDocumentBuilder();
134+
135+
// ✅ Safe: Properly configured XML parser
136+
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
137+
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
138+
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
139+
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
140+
dbf.setXIncludeAware(false);
141+
dbf.setExpandEntityReferences(false);
142+
DocumentBuilder builder = dbf.newDocumentBuilder();`}
143+
lang="java"
144+
title="XML Parser Configuration Example"
145+
marks={['Vulnerable', 'Vulnerable', 'Safe']}
146+
/>
147+
</div>
148+
</Card>
149+
</div>
150+
151+
120152
</div>
121153

122154
For more information on using Code PathFinder with Java, see our [documentation](/overview).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @name XXEConfig
3+
* @description Detects insecure XML parsers and configurations that could lead to XXE attacks
4+
* @kind problem
5+
* @id java/XXEConfig
6+
* @problem.severity warning
7+
* @security-severity 8.0
8+
* @precision high
9+
* @tags security
10+
* external/cwe/cwe-611
11+
* @ruleprovider java
12+
*/
13+
14+
FROM method_invocation AS mi
15+
WHERE mi.getName() == "setFeature" &&
16+
("http://xml.org/sax/features/external-parameter-entities" in mi.getArgumentName() &&
17+
"true" in mi.getArgumentName()) ||
18+
("http://xml.org/sax/features/external-general-entities" in mi.getArgumentName() &&
19+
"true" in mi.getArgumentName()) ||
20+
("http://apache.org/xml/features/disallow-doctype-decl" in mi.getArgumentName() &&
21+
"false" in mi.getArgumentName())
22+
SELECT mi.getName(), "XML External Entity (XXE) attack vulnerability"

sourcecode-parser/cmd/ci_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestLoadRules(t *testing.T) {
122122
name: "Local rules directory",
123123
rulesDirectory: "../../pathfinder-rules",
124124
isHosted: false,
125-
expectedRules: 12,
125+
expectedRules: 13,
126126
expectError: false,
127127
},
128128
{

test-src/android/app/src/main/java/com/ivb/udacity/movieDetailFragment.java

+12
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ protected void getTrailer(final LinearLayout youtubeViewHolder) {
173173
@Override
174174
public void success(movieYoutubeModal movieYoutubeModal, Response response) {
175175
youtubeViewHolder.setPadding(5, 10, 5, 0);
176+
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
177+
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false);
178+
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", true);
179+
dbf.newDocumentBuilder();
176180
com.ivb.udacity.modal.trailer.Results[] trailer = movieYoutubeModal.getResults();
177181
if (trailer.length > 0) {
178182
shareYoutubeID = trailer[0].getKey();
@@ -211,6 +215,14 @@ public void onClick(View v) {
211215
errmsg.setLayoutParams(params);
212216
errmsg.setText("That's Bad Luck,No Trailers Found!Check later");
213217
youtubeViewHolder.addView(errmsg);
218+
219+
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
220+
dbf.setFeature("http://xml.org/sax/features/external-general-entities", true);
221+
dbf.newDocumentBuilder();
222+
223+
DocumentBuilderFactory dbf2 = DocumentBuilderFactory.newInstance();
224+
dbf2.setFeature("http://xml.org/sax/features/external-parameter-entities", true);
225+
dbf2.newDocumentBuilder();
214226
}
215227
}
216228

0 commit comments

Comments
 (0)