Skip to content

Commit f07e084

Browse files
committed
Add CWE support for osv
Signed-off-by: ziadhany <ziadhany2016@gmail.com>
1 parent 6b15218 commit f07e084

4 files changed

Lines changed: 224 additions & 0 deletions

File tree

vulnerabilities/importers/osv.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from vulnerabilities.severity_systems import SCORING_SYSTEMS
2828
from vulnerabilities.utils import build_description
2929
from vulnerabilities.utils import dedupe
30+
from vulnerabilities.utils import get_cwe_id
3031

3132
logger = logging.getLogger(__name__)
3233

@@ -74,13 +75,17 @@ def parse_advisory_data(raw_data: dict, supported_ecosystem) -> Optional[Advisor
7475
fixed_version=version,
7576
)
7677
)
78+
database_specific = raw_data.get("database_specific") or {}
79+
cwe_ids = database_specific.get("cwe_ids") or []
80+
weaknesses = list(map(get_cwe_id, cwe_ids))
7781

7882
return AdvisoryData(
7983
aliases=aliases,
8084
summary=summary,
8185
references=references,
8286
affected_packages=affected_packages,
8387
date_published=date_published,
88+
weaknesses=weaknesses,
8489
)
8590

8691

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"aliases": [
3+
"CVE-2022-24840",
4+
"GHSA-4w8f-hjm9-xwgf"
5+
],
6+
"summary": "Path Traversal in django-s3file\n### Impact\n\nIt was possible to traverse the entire AWS S3 bucket and in most cases to access or delete files.\nThe issue was discovered by the maintainer. There were no reports of the vulnerability\nbeing known to or exploited by a third party, before the release of the patch.\n\nIf the `AWS_LOCATION` setting was set, traversal was limited to that location only.\nIf all your files handling views (like form views) require authentication or special permission, the thread is limited to privileged users.\n\n### Patches\n\nThe vulnerability has been fixed in version 5.5.1 and above.\n\n### Workarounds\n\nThere is no feasible workaround. We must urge all users to immediately updated to a patched version.\n\n### Detailed attack vector description\n\nAn attacker may use a request with malicious form data to traverse the entire AWS S3 bucket and perform destructive operations.\n\nAn attack could look as follows:\n```bash\ncurl -X POST -F \"s3file=file\" -F \"file=/priviliged/location/secrets.txt\" https://www.example.com/any/path/will/work/\n```\n\nThis will result in a request with files set and opened:\n\n```python\n>>> request.FILES.getlist(\"file\")\n[File(\"/priviliged/location/secrets.txt\")]\n```\n\nSince this behavior is injected via a middleware, any view can be called this way and will carry any files defined by the attacker.\n\nVia the `s3file` form field, any input name can be specified, including multiple inputs. For each input, multiple files can be freely\npicked of the S3 bucket.\n\n#### Scenarios and their practicality\n\nThere are four scenarios that would be considered practical in most setups:\n\n1. Illegal file injection,\n2. file deletion,\n3. file retrieval & tree traversal.\n4. code injection & remote code execution.\n\n##### File deletion\n\nAn attacker knows the location of a privileged file, like a static asset. Next, the file is injected into a form view. The upload to function will move the file to a new location. This is effectively deleting the file, since the previous references to it are invalid, and will cause S3 to return a 404. Furthermore, the new location is unknown to the site operator.\n\n##### File retrieval & tree traversal\n\nAn attacker knows the URL of a secret file and injects it into a form view. The view will move the file to a public location, making it accessible to the attacker. Since most form views will not be rate limited, this could also be used to guess files and traverse the file tree.\n\n##### Illegal file injection\n\nAn attacker uses any form to upload a file to the temporary upload location. Next, the attacker injects that file into a request, does not validate the contents or is not equipped to handle the mime type. The latter could be used as a potential DOS vector.\n\nIn practice, this is not a practical risk in most hardened setup. Files should always be sanitized before processing, since files can be included in a request even without this security issues.\n\n### For more information\nIf you have any questions or comments about this advisory:\n* Open an issue on [GitHub](https://github.com/codingjoe/django-s3file/issues)\n* Email us at [johannes@maron.family](mailto:johannes@maron.family)",
7+
"affected_packages": [
8+
{
9+
"package": {
10+
"type": "pypi",
11+
"namespace": null,
12+
"name": "django-s3file",
13+
"version": null,
14+
"qualifiers": null,
15+
"subpath": null
16+
},
17+
"affected_version_range": null,
18+
"fixed_version": "5.5.1"
19+
}
20+
],
21+
"references": [
22+
{
23+
"reference_id": "",
24+
"url": "https://github.com/codingjoe/django-s3file/security/advisories/GHSA-4w8f-hjm9-xwgf",
25+
"severities": [
26+
{
27+
"system": "cvssv3.1",
28+
"value": "9.1",
29+
"scoring_elements": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N"
30+
},
31+
{
32+
"system": "generic_textual",
33+
"value": "CRITICAL",
34+
"scoring_elements": ""
35+
}
36+
]
37+
},
38+
{
39+
"reference_id": "",
40+
"url": "https://nvd.nist.gov/vuln/detail/CVE-2022-24840",
41+
"severities": [
42+
{
43+
"system": "cvssv3.1",
44+
"value": "9.1",
45+
"scoring_elements": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N"
46+
},
47+
{
48+
"system": "generic_textual",
49+
"value": "CRITICAL",
50+
"scoring_elements": ""
51+
}
52+
]
53+
},
54+
{
55+
"reference_id": "",
56+
"url": "https://github.com/codingjoe/django-s3file/commit/68ccd2c621a40eb66fdd6af2be9d5fcc9c373318",
57+
"severities": [
58+
{
59+
"system": "cvssv3.1",
60+
"value": "9.1",
61+
"scoring_elements": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N"
62+
},
63+
{
64+
"system": "generic_textual",
65+
"value": "CRITICAL",
66+
"scoring_elements": ""
67+
}
68+
]
69+
},
70+
{
71+
"reference_id": "",
72+
"url": "https://github.com/codingjoe/django-s3file",
73+
"severities": [
74+
{
75+
"system": "cvssv3.1",
76+
"value": "9.1",
77+
"scoring_elements": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N"
78+
},
79+
{
80+
"system": "generic_textual",
81+
"value": "CRITICAL",
82+
"scoring_elements": ""
83+
}
84+
]
85+
},
86+
{
87+
"reference_id": "",
88+
"url": "https://github.com/codingjoe/django-s3file/releases/tag/5.5.1",
89+
"severities": [
90+
{
91+
"system": "cvssv3.1",
92+
"value": "9.1",
93+
"scoring_elements": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N"
94+
},
95+
{
96+
"system": "generic_textual",
97+
"value": "CRITICAL",
98+
"scoring_elements": ""
99+
}
100+
]
101+
},
102+
{
103+
"reference_id": "",
104+
"url": "https://github.com/pypa/advisory-database/tree/main/vulns/django-s3file/PYSEC-2022-208.yaml",
105+
"severities": [
106+
{
107+
"system": "cvssv3.1",
108+
"value": "9.1",
109+
"scoring_elements": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N"
110+
},
111+
{
112+
"system": "generic_textual",
113+
"value": "CRITICAL",
114+
"scoring_elements": ""
115+
}
116+
]
117+
}
118+
],
119+
"date_published": "2022-06-06T21:24:24+00:00",
120+
"weaknesses": [
121+
22,
122+
96
123+
]
124+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-4w8f-hjm9-xwgf",
4+
"modified": "2022-06-06T21:24:24Z",
5+
"published": "2022-06-06T21:24:24Z",
6+
"aliases": [
7+
"CVE-2022-24840"
8+
],
9+
"summary": "Path Traversal in django-s3file",
10+
"details": "### Impact\n\nIt was possible to traverse the entire AWS S3 bucket and in most cases to access or delete files.\nThe issue was discovered by the maintainer. There were no reports of the vulnerability\nbeing known to or exploited by a third party, before the release of the patch.\n\nIf the `AWS_LOCATION` setting was set, traversal was limited to that location only.\nIf all your files handling views (like form views) require authentication or special permission, the thread is limited to privileged users.\n\n### Patches\n\nThe vulnerability has been fixed in version 5.5.1 and above.\n\n### Workarounds\n\nThere is no feasible workaround. We must urge all users to immediately updated to a patched version.\n\n### Detailed attack vector description\n\nAn attacker may use a request with malicious form data to traverse the entire AWS S3 bucket and perform destructive operations.\n\nAn attack could look as follows:\n```bash\ncurl -X POST -F \"s3file=file\" -F \"file=/priviliged/location/secrets.txt\" https://www.example.com/any/path/will/work/\n```\n\nThis will result in a request with files set and opened:\n\n```python\n>>> request.FILES.getlist(\"file\")\n[File(\"/priviliged/location/secrets.txt\")]\n```\n\nSince this behavior is injected via a middleware, any view can be called this way and will carry any files defined by the attacker.\n\nVia the `s3file` form field, any input name can be specified, including multiple inputs. For each input, multiple files can be freely\npicked of the S3 bucket.\n\n#### Scenarios and their practicality\n\nThere are four scenarios that would be considered practical in most setups:\n\n1. Illegal file injection,\n2. file deletion,\n3. file retrieval & tree traversal.\n4. code injection & remote code execution.\n\n##### File deletion\n\nAn attacker knows the location of a privileged file, like a static asset. Next, the file is injected into a form view. The upload to function will move the file to a new location. This is effectively deleting the file, since the previous references to it are invalid, and will cause S3 to return a 404. Furthermore, the new location is unknown to the site operator.\n\n##### File retrieval & tree traversal\n\nAn attacker knows the URL of a secret file and injects it into a form view. The view will move the file to a public location, making it accessible to the attacker. Since most form views will not be rate limited, this could also be used to guess files and traverse the file tree.\n\n##### Illegal file injection\n\nAn attacker uses any form to upload a file to the temporary upload location. Next, the attacker injects that file into a request, does not validate the contents or is not equipped to handle the mime type. The latter could be used as a potential DOS vector.\n\nIn practice, this is not a practical risk in most hardened setup. Files should always be sanitized before processing, since files can be included in a request even without this security issues.\n\n### For more information\nIf you have any questions or comments about this advisory:\n* Open an issue on [GitHub](https://github.com/codingjoe/django-s3file/issues)\n* Email us at [johannes@maron.family](mailto:johannes@maron.family)\n",
11+
"severity": [
12+
{
13+
"type": "CVSS_V3",
14+
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N"
15+
}
16+
],
17+
"affected": [
18+
{
19+
"package": {
20+
"ecosystem": "PyPI",
21+
"name": "django-s3file"
22+
},
23+
"ecosystem_specific": {
24+
"affected_functions": [
25+
"s3file.forms.S3FileInputMixin",
26+
"s3file.forms.S3FileInputMixin.build_attrs",
27+
"s3file.middleware.S3FileMiddleware.__call__",
28+
"s3file.middleware.S3FileMiddleware.get_files_from_storage"
29+
]
30+
},
31+
"ranges": [
32+
{
33+
"type": "ECOSYSTEM",
34+
"events": [
35+
{
36+
"introduced": "0"
37+
},
38+
{
39+
"fixed": "5.5.1"
40+
}
41+
]
42+
}
43+
]
44+
}
45+
],
46+
"references": [
47+
{
48+
"type": "WEB",
49+
"url": "https://github.com/codingjoe/django-s3file/security/advisories/GHSA-4w8f-hjm9-xwgf"
50+
},
51+
{
52+
"type": "ADVISORY",
53+
"url": "https://nvd.nist.gov/vuln/detail/CVE-2022-24840"
54+
},
55+
{
56+
"type": "WEB",
57+
"url": "https://github.com/codingjoe/django-s3file/commit/68ccd2c621a40eb66fdd6af2be9d5fcc9c373318"
58+
},
59+
{
60+
"type": "PACKAGE",
61+
"url": "https://github.com/codingjoe/django-s3file"
62+
},
63+
{
64+
"type": "WEB",
65+
"url": "https://github.com/codingjoe/django-s3file/releases/tag/5.5.1"
66+
},
67+
{
68+
"type": "WEB",
69+
"url": "https://github.com/pypa/advisory-database/tree/main/vulns/django-s3file/PYSEC-2022-208.yaml"
70+
}
71+
],
72+
"database_specific": {
73+
"cwe_ids": [
74+
"CWE-22",
75+
"CWE-96"
76+
],
77+
"severity": "CRITICAL",
78+
"github_reviewed": true,
79+
"github_reviewed_at": "2022-06-06T21:24:24Z",
80+
"nvd_published_at": "2022-06-09T04:15:00Z"
81+
}
82+
}

vulnerabilities/tests/test_pysec.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,16 @@ def test_to_advisories_without_summary(self):
4343
expected_file=expected_file,
4444
regen=REGEN,
4545
)
46+
47+
def test_to_advisories_with_cwe(self):
48+
with open(os.path.join(TEST_DATA, "pysec-advisory_with_cwe.json")) as f:
49+
mock_response = json.load(f)
50+
51+
results = parse_advisory_data(mock_response, "pypi").to_dict()
52+
53+
expected_file = os.path.join(TEST_DATA, "pysec-advisories_with_cwe-expected.json")
54+
check_results_against_json(
55+
results=results,
56+
expected_file=expected_file,
57+
regen=REGEN,
58+
)

0 commit comments

Comments
 (0)