-
Notifications
You must be signed in to change notification settings - Fork 115
Normalize OWASP cheat sheet references #865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Bornunique911
wants to merge
12
commits into
OWASP:main
from
Bornunique911:review/issue-471-cheatsheet-references
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2fbfb07
Add OWASP Top 10 and API importer support
Bornunique911 43a9e0f
Fix cheat sheet parser test expectations on importer branches
Bornunique911 eae44eb
Use official OWASP cheat sheet URLs in importer branches
Bornunique911 9f51787
Add OWASP AI resource importer support
Bornunique911 6440ab5
Add OWASP Kubernetes importer support
Bornunique911 eea9415
Normalize OWASP cheat sheet references
Bornunique911 3851d1d
Refactor links definition in cheatsheets parser test for improved rea…
Bornunique911 5a62823
Update hyperlinks and normalize link access in OWASP parser tests and…
Bornunique911 d966a5c
Enhance error handling and deduplication logic in Cheatsheets parser
Bornunique911 fa5893b
Add assertions for K09 and K10 in OWASP Kubernetes Top Ten 2022 parse…
Bornunique911 a59e914
Refactor secret entry retrieval in cheatsheets parser test for clarit…
Bornunique911 8b80b4d
Refactor secret entry retrieval for improved readability in cheatshee…
Bornunique911 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import unittest | ||
|
|
||
| from application import create_app, sqla # type: ignore | ||
| from application.database import db | ||
| from application.defs import cre_defs as defs | ||
| from application.prompt_client import prompt_client | ||
| from application.utils.external_project_parsers.parsers import owasp_aisvs | ||
|
|
||
|
|
||
| class TestOwaspAisvsParser(unittest.TestCase): | ||
| def tearDown(self) -> None: | ||
| sqla.session.remove() | ||
| sqla.drop_all() | ||
| self.app_context.pop() | ||
|
|
||
| def setUp(self) -> None: | ||
| self.app = create_app(mode="test") | ||
| self.app_context = self.app.app_context() | ||
| self.app_context.push() | ||
| sqla.create_all() | ||
| self.collection = db.Node_collection() | ||
|
|
||
| def test_parse(self) -> None: | ||
| for cre_id, name in [ | ||
| ("227-045", "Identify sensitive data and subject it to a policy"), | ||
| ( | ||
| "307-507", | ||
| "Allow only trusted sources both build time and runtime; therefore perform integrity checks on all resources and code", | ||
| ), | ||
| ( | ||
| "162-655", | ||
| "Documentation of all components' business or security function", | ||
| ), | ||
| ]: | ||
| self.collection.add_cre(defs.CRE(id=cre_id, name=name, description="")) | ||
|
|
||
| result = owasp_aisvs.OwaspAisvs().parse( | ||
| self.collection, prompt_client.PromptHandler(database=self.collection) | ||
| ) | ||
|
|
||
| entries = result.results["OWASP AI Security Verification Standard (AISVS)"] | ||
| self.assertEqual(14, len(entries)) | ||
| self.assertEqual("AISVS1", entries[0].sectionID) | ||
| self.assertEqual( | ||
| "Training Data Governance & Bias Management", entries[0].section | ||
| ) | ||
| self.assertEqual( | ||
| "https://github.com/OWASP/AISVS/blob/main/1.0/en/0x10-C01-Training-Data-Governance.md", | ||
| entries[0].hyperlink, | ||
| ) | ||
| self.assertEqual( | ||
| ["227-045", "307-507"], [link.document.id for link in entries[0].links] | ||
| ) | ||
| self.assertEqual("AISVS14", entries[-1].sectionID) | ||
| self.assertEqual( | ||
| "Human Oversight, Accountability & Governance", entries[-1].section | ||
| ) | ||
| self.assertEqual( | ||
| "https://github.com/OWASP/AISVS/blob/main/1.0/en/0x10-C14-Human-Oversight.md", | ||
| entries[-1].hyperlink, | ||
| ) | ||
| self.assertEqual(["162-655"], [link.document.id for link in entries[-1].links]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import unittest | ||
|
|
||
| from application import create_app, sqla # type: ignore | ||
| from application.database import db | ||
| from application.defs import cre_defs as defs | ||
| from application.prompt_client import prompt_client | ||
| from application.utils.external_project_parsers.parsers import owasp_api_top10_2023 | ||
|
|
||
|
|
||
| class TestOwaspApiTop10_2023Parser(unittest.TestCase): | ||
| def tearDown(self) -> None: | ||
| sqla.session.remove() | ||
| sqla.drop_all() | ||
| self.app_context.pop() | ||
|
|
||
| def setUp(self) -> None: | ||
| self.app = create_app(mode="test") | ||
| self.app_context = self.app.app_context() | ||
| self.app_context.push() | ||
| sqla.create_all() | ||
| self.collection = db.Node_collection() | ||
|
|
||
| def test_parse(self) -> None: | ||
| for cre_id, name in [ | ||
| ("304-667", "Protect API against unauthorized access/modification (IDOR)"), | ||
| ("724-770", "Technical application access control"), | ||
| ("715-223", "Ensure trusted origin of third party resources"), | ||
| ]: | ||
| self.collection.add_cre(defs.CRE(id=cre_id, name=name, description="")) | ||
|
|
||
| result = owasp_api_top10_2023.OwaspApiTop10_2023().parse( | ||
| self.collection, prompt_client.PromptHandler(database=self.collection) | ||
| ) | ||
|
|
||
| entries = result.results["OWASP API Security Top 10 2023"] | ||
| self.assertEqual(10, len(entries)) | ||
| self.assertEqual("API1", entries[0].sectionID) | ||
| self.assertEqual("Broken Object Level Authorization", entries[0].section) | ||
| self.assertEqual( | ||
| ["304-667", "724-770"], [link.document.id for link in entries[0].links] | ||
| ) | ||
| self.assertEqual("API10", entries[-1].sectionID) | ||
| self.assertEqual(["715-223"], [link.document.id for link in entries[-1].links]) |
54 changes: 54 additions & 0 deletions
54
application/tests/owasp_kubernetes_top10_2022_parser_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import unittest | ||
|
|
||
| from application import create_app, sqla # type: ignore | ||
| from application.database import db | ||
| from application.defs import cre_defs as defs | ||
| from application.prompt_client import prompt_client | ||
| from application.utils.external_project_parsers.parsers import ( | ||
| owasp_kubernetes_top10_2022, | ||
| ) | ||
|
|
||
|
|
||
| class TestOwaspKubernetesTop10_2022Parser(unittest.TestCase): | ||
| def tearDown(self) -> None: | ||
| sqla.session.remove() | ||
| sqla.drop_all() | ||
| self.app_context.pop() | ||
|
|
||
| def setUp(self) -> None: | ||
| self.app = create_app(mode="test") | ||
| self.app_context = self.app.app_context() | ||
| self.app_context.push() | ||
| sqla.create_all() | ||
| self.collection = db.Node_collection() | ||
|
|
||
| def test_parse(self) -> None: | ||
| for cre_id, name in [ | ||
| ("233-748", "Configuration hardening"), | ||
| ("486-813", "Configuration"), | ||
| ("053-751", "Force build pipeline to check outdated/insecure components"), | ||
| ]: | ||
| self.collection.add_cre(defs.CRE(id=cre_id, name=name, description="")) | ||
|
|
||
| result = owasp_kubernetes_top10_2022.OwaspKubernetesTop10_2022().parse( | ||
| self.collection, prompt_client.PromptHandler(database=self.collection) | ||
| ) | ||
|
|
||
| entries = result.results["OWASP Kubernetes Top Ten 2022"] | ||
| self.assertEqual(10, len(entries)) | ||
| self.assertEqual("K01", entries[0].sectionID) | ||
| self.assertEqual("Insecure Workload Configurations", entries[0].section) | ||
| self.assertEqual( | ||
| ["233-748", "486-813"], [link.document.id for link in entries[0].links] | ||
| ) | ||
|
|
||
| # K09 intentionally shares the same CRE ids as K01 for this version. | ||
| # In OWASP Kubernetes 2025, K07 aggregates 2022 K09 and K10, so K09 maps | ||
| # to the same configuration-focused CREs while K10 covers outdated/vulnerable components. | ||
| self.assertEqual("K09", entries[8].sectionID) | ||
| self.assertEqual( | ||
| ["233-748", "486-813"], [link.document.id for link in entries[8].links] | ||
| ) | ||
|
|
||
| self.assertEqual("K10", entries[-1].sectionID) | ||
| self.assertEqual(["053-751"], [link.document.id for link in entries[-1].links]) |
102 changes: 102 additions & 0 deletions
102
application/tests/owasp_kubernetes_top10_2025_parser_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import unittest | ||
| import tempfile | ||
| from pathlib import Path | ||
|
|
||
| from application import create_app, sqla # type: ignore | ||
| from application.database import db | ||
| from application.defs import cre_defs as defs | ||
| from application.prompt_client import prompt_client | ||
| from application.utils.external_project_parsers.parsers import ( | ||
| owasp_kubernetes_top10_2025, | ||
| ) | ||
|
|
||
|
|
||
| class TestOwaspKubernetesTop10_2025Parser(unittest.TestCase): | ||
| def tearDown(self) -> None: | ||
| sqla.session.remove() | ||
| sqla.drop_all() | ||
| self.app_context.pop() | ||
|
|
||
| def setUp(self) -> None: | ||
| self.app = create_app(mode="test") | ||
| self.app_context = self.app.app_context() | ||
| self.app_context.push() | ||
| sqla.create_all() | ||
| self.collection = db.Node_collection() | ||
|
|
||
| def test_parse(self) -> None: | ||
| for cre_id, name in [ | ||
| ("233-748", "Configuration hardening"), | ||
| ("486-813", "Configuration"), | ||
| ("148-420", "Log integrity"), | ||
| ("402-706", "Log relevant"), | ||
| ("843-841", "Log discretely"), | ||
| ]: | ||
| self.collection.add_cre(defs.CRE(id=cre_id, name=name, description="")) | ||
|
|
||
| result = owasp_kubernetes_top10_2025.OwaspKubernetesTop10_2025().parse( | ||
| self.collection, prompt_client.PromptHandler(database=self.collection) | ||
| ) | ||
|
|
||
| entries = result.results["OWASP Kubernetes Top Ten 2025 (Draft)"] | ||
| self.assertEqual(10, len(entries)) | ||
| self.assertEqual("K01", entries[0].sectionID) | ||
| self.assertEqual("Insecure Workload Configurations", entries[0].section) | ||
| self.assertEqual( | ||
| ["233-748", "486-813"], [link.document.id for link in entries[0].links] | ||
| ) | ||
| self.assertEqual("K10", entries[-1].sectionID) | ||
| self.assertEqual( | ||
| ["148-420", "402-706", "843-841"], | ||
| [link.document.id for link in entries[-1].links], | ||
| ) | ||
|
|
||
| def test_parse_falls_back_to_2022_mapping_when_2025_links_missing(self) -> None: | ||
| self.collection.add_cre( | ||
| defs.CRE(id="148-420", name="Log integrity", description="") | ||
| ) | ||
|
|
||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| tmp_path = Path(tmpdir) | ||
| current_file = tmp_path / "k8s_2025.json" | ||
| fallback_file = tmp_path / "k8s_2022.json" | ||
| current_file.write_text( | ||
| """ | ||
| [ | ||
| { | ||
| "section_id": "K10", | ||
| "section": "Inadequate Logging And Monitoring", | ||
| "hyperlink": "https://example.com/k10", | ||
| "cre_ids": ["999-999"], | ||
| "fallback_section_ids": ["K05"] | ||
| } | ||
| ] | ||
| """.strip(), | ||
| encoding="utf-8", | ||
| ) | ||
| fallback_file.write_text( | ||
| """ | ||
| [ | ||
| { | ||
| "section_id": "K05", | ||
| "section": "Inadequate Logging and Monitoring", | ||
| "hyperlink": "https://example.com/k05", | ||
| "cre_ids": ["148-420"] | ||
| } | ||
| ] | ||
| """.strip(), | ||
| encoding="utf-8", | ||
| ) | ||
|
|
||
| parser = owasp_kubernetes_top10_2025.OwaspKubernetesTop10_2025() | ||
| parser.data_file = current_file | ||
| parser.fallback_data_file = fallback_file | ||
|
|
||
| result = parser.parse( | ||
| self.collection, | ||
| prompt_client.PromptHandler(database=self.collection), | ||
| ) | ||
|
|
||
| entries = result.results["OWASP Kubernetes Top Ten 2025 (Draft)"] | ||
| self.assertEqual(1, len(entries)) | ||
| self.assertEqual(["148-420"], [link.document.id for link in entries[0].links]) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import unittest | ||
|
|
||
| from application import create_app, sqla # type: ignore | ||
| from application.database import db | ||
| from application.defs import cre_defs as defs | ||
| from application.prompt_client import prompt_client | ||
| from application.utils.external_project_parsers.parsers import owasp_llm_top10_2025 | ||
|
|
||
|
|
||
| class TestOwaspLlmTop10_2025Parser(unittest.TestCase): | ||
| def tearDown(self) -> None: | ||
| sqla.session.remove() | ||
| sqla.drop_all() | ||
| self.app_context.pop() | ||
|
|
||
| def setUp(self) -> None: | ||
| self.app = create_app(mode="test") | ||
| self.app_context = self.app.app_context() | ||
| self.app_context.push() | ||
| sqla.create_all() | ||
| self.collection = db.Node_collection() | ||
|
|
||
| def test_parse(self) -> None: | ||
| for cre_id, name in [ | ||
| ("161-451", "Output encoding and injection prevention"), | ||
| ("064-808", "Encode output context-specifically"), | ||
| ("760-764", "Injection protection"), | ||
| ("623-550", "Denial Of Service protection"), | ||
| ]: | ||
| self.collection.add_cre(defs.CRE(id=cre_id, name=name, description="")) | ||
|
|
||
| result = owasp_llm_top10_2025.OwaspLlmTop10_2025().parse( | ||
| self.collection, prompt_client.PromptHandler(database=self.collection) | ||
| ) | ||
|
|
||
| entries = result.results["OWASP Top 10 for LLM and Gen AI Apps 2025"] | ||
| self.assertEqual(10, len(entries)) | ||
| self.assertEqual("LLM01", entries[0].sectionID) | ||
| self.assertEqual("Prompt Injection", entries[0].section) | ||
| self.assertEqual( | ||
| ["161-451", "760-764"], [link.document.id for link in entries[0].links] | ||
| ) | ||
| self.assertEqual(["064-808"], [link.document.id for link in entries[4].links]) | ||
| self.assertEqual("LLM10", entries[-1].sectionID) | ||
| self.assertEqual(["623-550"], [link.document.id for link in entries[-1].links]) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.