Skip to content

Commit

Permalink
sets default enabled rules to phase 1 rules
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraschauer committed Jul 5, 2024
1 parent 70d9401 commit 2ee7fe3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 31 deletions.
4 changes: 2 additions & 2 deletions prospector/core/prospector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from git.version_to_tag import get_possible_tags
from llm.llm_service import LLMService
from log.logger import get_level, logger, pretty_log
from rules.rules import apply_rules
from rules.rules import RULES_PHASE_1, apply_rules
from stats.execution import (
Counter,
ExecutionTimer,
Expand Down Expand Up @@ -66,7 +66,7 @@ def prospector( # noqa: C901
use_backend: str = USE_BACKEND_ALWAYS,
git_cache: str = "/tmp/git_cache",
limit_candidates: int = MAX_CANDIDATES,
enabled_rules: List[str] = [],
enabled_rules: List[str] = [rule.id for rule in RULES_PHASE_1],
tag_commits: bool = True,
silent: bool = False,
use_llm_repository_url: bool = False,
Expand Down
1 change: 1 addition & 0 deletions prospector/llm/models/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def _call(

try:
response = requests.post(endpoint, headers=headers, json=data)
response.raise_for_status()
return self.parse(response.json())
except requests.exceptions.HTTPError as http_error:
logger.error(
Expand Down
1 change: 1 addition & 0 deletions prospector/llm/models/mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def _call(

try:
response = requests.post(endpoint, headers=headers, json=data)
response.raise_for_status()
return self.parse(response.json())
except requests.exceptions.HTTPError as http_error:
logger.error(
Expand Down
4 changes: 2 additions & 2 deletions prospector/llm/models/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def _identifying_params(self) -> Dict[str, Any]:
def _call(
self, prompt: str, stop: Optional[List[str]] = None, **kwargs: Any
) -> str:
# endpoint = f"{self.deployment_url}/chat/completions?api-version=2023-05-15"
endpoint = f"{self.deployment_url}/chat/cpletions?api-version=2023-05-15"
endpoint = f"{self.deployment_url}/chat/completions?api-version=2023-05-15"
headers = instantiation.get_headers(self.ai_core_sk_filepath)
data = {
"messages": [
Expand All @@ -45,6 +44,7 @@ def _call(

try:
response = requests.post(endpoint, headers=headers, json=data)
response.raise_for_status()
return self.parse(response.json())
except requests.exceptions.HTTPError as http_error:
logger.error(
Expand Down
28 changes: 1 addition & 27 deletions prospector/rules/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,30 +412,6 @@ def apply(self, candidate: Commit, advisory_record: AdvisoryRecord):
return False


class CommitIsSecurityRelevant(Rule):
"""Matches commits that are deemed security relevant by the commit classification service."""

def apply(
self,
candidate: Commit,
) -> bool:
# temperature saved in LLMService's model
temperature = self.llm_service.model._identifying_params.get("temperature")
data = {
"temperature": temperature,
"diff": "\n".join(candidate.diff),
}

response = requests.get("http://127.0.0.1:8001/predict", json=data)

prediction = response.json()["prediction"]
if prediction == "1":
self.message = "The commit was deemed security relevant by the commit classification service."
return True
else:
return False


RULES_PHASE_1: List[Rule] = [
VulnIdInMessage("VULN_ID_IN_MESSAGE", 64),
# CommitMentionedInAdv("COMMIT_IN_ADVISORY", 64),
Expand All @@ -456,6 +432,4 @@ def apply(
CommitHasTwins("COMMIT_HAS_TWINS", 2),
]

RULES_PHASE_2: List[Rule] = [
CommitIsSecurityRelevant("COMMIT_IS_SECURITY_RELEVANT", 32)
]
RULES_PHASE_2: List[Rule] = []

0 comments on commit 2ee7fe3

Please sign in to comment.