-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Code Vulnerability & ISA Evaluators #39882
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
f719a8e
first commit
w-javed 2dd0a12
added text
w-javed 0104cbc
updating assets
w-javed 1e6fcff
fix cspell
w-javed 7a48a66
fix cspell
w-javed af66dd7
test fix
w-javed 053d200
test fix
w-javed 990c227
refereshed assets
w-javed 8d02f15
refereshed assets
w-javed e0b421f
asset update
w-javed 924e718
asset update
w-javed 6632fb6
asset update
w-javed a08b48b
change to details
w-javed 36bbbb3
Merge branch 'main' into Code_Vuln_Evaluator
w-javed 45097e7
change to details
w-javed 0b3721b
assets
w-javed e7ea8d5
conflicts
w-javed 8744295
new assets
w-javed 097737d
new assets
w-javed 3f77f1e
new assets
w-javed cae008e
new assets
w-javed 32c360e
asset
w-javed 49b40bd
adding isa
w-javed 65eddd8
test added
w-javed 0f6098b
revert operation
w-javed 3463f04
Fix
w-javed deab4a8
Fix & asset
w-javed 74d835c
Fix & asset
w-javed 84c16e0
Fix & asset
w-javed 396517e
remove singleton
w-javed cd65ac8
remove singleton
w-javed ca7b695
fix
w-javed 00a6e68
resolved conflict
w-javed 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
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
5 changes: 5 additions & 0 deletions
5
...ation/azure-ai-evaluation/azure/ai/evaluation/_evaluators/_code_vulnerability/__init__.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,5 @@ | ||
| from ._code_vulnerability import CodeVulnerabilityEvaluator | ||
|
|
||
| __all__ = [ | ||
| "CodeVulnerabilityEvaluator", | ||
| ] |
120 changes: 120 additions & 0 deletions
120
...-ai-evaluation/azure/ai/evaluation/_evaluators/_code_vulnerability/_code_vulnerability.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,120 @@ | ||
| # --------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # --------------------------------------------------------- | ||
| from typing_extensions import overload, override | ||
| from typing import Union | ||
|
|
||
| from azure.ai.evaluation._common._experimental import experimental | ||
| from azure.ai.evaluation._common.constants import EvaluationMetrics | ||
| from azure.ai.evaluation._evaluators._common import RaiServiceEvaluatorBase | ||
|
|
||
|
|
||
| @experimental | ||
| class CodeVulnerabilityEvaluator(RaiServiceEvaluatorBase[Union[str, bool]]): | ||
| """ | ||
| Evaluates service-based code vulnerability for a given query and response for a single-turn evaluation only, | ||
| where query represents the user query or code before the completion, and response represents the code recommended by the assistant. | ||
|
|
||
| The code vulnerability evaluation checks for vulnerabilities in the following coding languages: | ||
|
|
||
| - Python | ||
| - Java | ||
| - C++ | ||
| - C# | ||
| - Go | ||
| - Javascript | ||
| - SQL | ||
|
|
||
| The code vulnerability evaluation identifies the following vulnerabilities: | ||
|
|
||
| - path-injection | ||
| - sql-injection | ||
| - code-injection | ||
| - stack-trace-exposure | ||
| - incomplete-url-substring-sanitization | ||
| - flask-debug | ||
| - clear-text-logging-sensitive-data | ||
| - incomplete-hostname-regexp | ||
| - server-side-unvalidated-url-redirection | ||
| - weak-cryptographic-algorithm | ||
| - full-ssrf | ||
| - bind-socket-all-network-interfaces | ||
| - client-side-unvalidated-url-redirection | ||
| - likely-bugs | ||
| - reflected-xss | ||
| - clear-text-storage-sensitive-data | ||
| - tarslip | ||
| - hardcoded-credentials | ||
| - insecure-randomness | ||
|
|
||
| :param credential: The credential for connecting to Azure AI project. Required | ||
| :type credential: ~azure.core.credentials.TokenCredential | ||
| :param azure_ai_project: The scope of the Azure AI project. | ||
| It contains subscription id, resource group, and project name. | ||
| :type azure_ai_project: ~azure.ai.evaluation.AzureAIProject | ||
| :param kwargs: Additional arguments to pass to the evaluator. | ||
| :type kwargs: Any | ||
|
|
||
| .. admonition:: Example: | ||
|
|
||
| .. literalinclude:: ../samples/evaluation_samples_evaluate.py | ||
| :start-after: [START code_vulnerability_evaluator] | ||
| :end-before: [END code_vulnerability_evaluator] | ||
| :language: python | ||
| :dedent: 8 | ||
| :caption: Initialize and call a CodeVulnerabilityEvaluator with a query and response. | ||
|
|
||
| .. note:: | ||
|
|
||
| If this evaluator is supplied to the `evaluate` function, the metric | ||
| for the code vulnerability will be "code_vulnerability_label". | ||
| """ | ||
|
|
||
| id = "code_vulnerability" | ||
| """Evaluator identifier, experimental and to be used only with evaluation in cloud.""" | ||
|
|
||
| @override | ||
| def __init__( | ||
| self, | ||
| credential, | ||
| azure_ai_project, | ||
| ): | ||
| super().__init__( | ||
| eval_metric=EvaluationMetrics.CODE_VULNERABILITY, | ||
| azure_ai_project=azure_ai_project, | ||
| credential=credential, | ||
| ) | ||
|
|
||
| @overload | ||
| def __call__( | ||
| self, | ||
| *, | ||
| query: str, | ||
| response: str, | ||
| ): | ||
| """Evaluate a given query/response pair for code vulnerability | ||
|
|
||
| :keyword query: The query to be evaluated. | ||
| :paramtype query: str | ||
| :keyword response: The response to be evaluated. | ||
| :paramtype response: str | ||
| :return: The code vulnerability label. | ||
| :rtype: Dict[str, Union[str, bool]] | ||
| """ | ||
|
|
||
| @override | ||
| def __call__( # pylint: disable=docstring-missing-param | ||
| self, | ||
| *args, | ||
| **kwargs, | ||
| ): | ||
| """Evaluate code vulnerability. Accepts query and response for a single-turn evaluation only. | ||
|
|
||
| :keyword query: The query to be evaluated. | ||
| :paramtype query: Optional[str] | ||
| :keyword response: The response to be evaluated. | ||
| :paramtype response: Optional[str] | ||
| :rtype: Dict[str, Union[str, bool]] | ||
| """ | ||
|
|
||
| return super().__call__(*args, **kwargs) | ||
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
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
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.