-
Notifications
You must be signed in to change notification settings - Fork 115
Add OWASP AI resource importers #858
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
9
commits into
OWASP:main
from
Bornunique911:review/issue-471-ai-resource-importers
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a8fe162
Add OWASP Top 10 and API importer support
Bornunique911 eefe46e
Fix cheat sheet parser test expectations on importer branches
Bornunique911 4a64144
Use official OWASP cheat sheet URLs in importer branches
Bornunique911 cc63aa9
Add OWASP AI resource importer support
Bornunique911 9a0d65c
Refactor links definition in cheatsheets parser test for improved rea…
Bornunique911 5c87402
Add support for OWASP Top 10 and AISVS resources in the resource impo…
Bornunique911 3d764f7
Refactor variable name for clarity in OWASP LLM Top 10 parser test
Bornunique911 c49cda3
Add a production guard before direct GA recomputation.
Bornunique911 a1c8289
Update application/cmd/cre_main.py
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
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,66 @@ | ||
| 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-Integrity-and-Traceability.md", | ||
| entries[0].hyperlink, | ||
| ) | ||
| self.assertEqual( | ||
| ["227-045", "307-507"], | ||
| [link.document.id for link in entries[0].links], | ||
| ) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| 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,47 @@ | ||
| 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], | ||
| ) |
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]) |
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,80 @@ | ||
| 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_top10_2025 | ||
|
|
||
|
|
||
| class TestOwaspTop10_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: | ||
| self.collection.add_cre( | ||
| defs.CRE(id="177-260", name="Session management", description="") | ||
| ) | ||
| self.collection.add_cre( | ||
| defs.CRE( | ||
| id="117-371", | ||
| name="Use a centralized access control mechanism", | ||
| description="", | ||
| ) | ||
| ) | ||
| self.collection.add_cre( | ||
| defs.CRE( | ||
| id="724-770", | ||
| name="Technical application access control", | ||
| description="", | ||
| ) | ||
| ) | ||
| self.collection.add_cre( | ||
| defs.CRE( | ||
| id="031-447", name="Whitelist all external (HTTP) input", description="" | ||
| ) | ||
| ) | ||
| self.collection.add_cre( | ||
| defs.CRE( | ||
| id="064-808", name="Encode output context-specifically", description="" | ||
| ) | ||
| ) | ||
| self.collection.add_cre( | ||
| defs.CRE(id="760-764", name="Injection protection", description="") | ||
| ) | ||
| self.collection.add_cre( | ||
| defs.CRE(id="513-183", name="Error handling", description="") | ||
| ) | ||
|
|
||
| result = owasp_top10_2025.OwaspTop10_2025().parse( | ||
| self.collection, | ||
| prompt_client.PromptHandler(database=self.collection), | ||
| ) | ||
|
|
||
| entries = result.results["OWASP Top 10 2025"] | ||
| self.assertEqual(10, len(entries)) | ||
| self.assertEqual("A01", entries[0].sectionID) | ||
| self.assertEqual("Broken Access Control", entries[0].section) | ||
| self.assertEqual( | ||
| "https://owasp.org/Top10/2025/A01_2025-Broken_Access_Control/", | ||
| entries[0].hyperlink, | ||
| ) | ||
| self.assertEqual( | ||
| ["117-371", "177-260", "724-770"], | ||
| [link.document.id for link in entries[0].links], | ||
| ) | ||
| self.assertEqual( | ||
| ["031-447", "064-808", "760-764"], | ||
| [link.document.id for link in entries[4].links], | ||
| ) | ||
| self.assertEqual("A10", entries[-1].sectionID) | ||
| self.assertEqual(["513-183"], [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.