From 29362aed30b87f5f788386b03aa4315d286e6cb9 Mon Sep 17 00:00:00 2001 From: sjay8 Date: Sun, 9 Mar 2025 13:48:32 -0700 Subject: [PATCH 1/8] Fixed issue 137: ensuring http/https with :// is present --- agentic_security/http_spec.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/agentic_security/http_spec.py b/agentic_security/http_spec.py index 544ebb1..161955c 100644 --- a/agentic_security/http_spec.py +++ b/agentic_security/http_spec.py @@ -1,6 +1,7 @@ import base64 from enum import Enum +from urllib.parse import urlparse import httpx from pydantic import BaseModel @@ -14,7 +15,7 @@ class Modality(Enum): FILES = 3 MIXED = 4 - +# encoding the image data fro def encode_image_base64_by_url(url: str = "https://github.com/fluidicon.png") -> str: """Encode image data to base64 from a URL""" response = httpx.get(url) @@ -39,10 +40,11 @@ class LLMSpec(BaseModel): headers: dict body: str has_files: bool = False - has_image: bool = False + has_image: bool = Fa has_audio: bool = False @classmethod + # class method6 def from_string(cls, http_spec: str): try: return parse_http_spec(http_spec) @@ -78,6 +80,8 @@ class LLMSpec(BaseModel): if self.has_audio and not encoded_audio: raise ValueError("Audio is required for this request.") + + async def probe( self, prompt: str, encoded_image: str = "", encoded_audio: str = "", files={} ) -> httpx.Response: @@ -144,9 +148,7 @@ def parse_http_spec(http_spec: str) -> LLMSpec: """Parses an HTTP specification string into a LLMSpec object. Args: - http_spec (str): A string representing an HTTP specification. - - Returns: + http_spec (str): A string representing an HTTP specification. Returns: LLMSpec: An object representing the parsed HTTP specification, with attributes for the method, URL, headers, and body. """ from agentic_security.core.app import get_secrets @@ -159,6 +161,17 @@ def parse_http_spec(http_spec: str) -> LLMSpec: # Extract the method and URL from the first line method, url = lines[0].split(" ")[0:2] + # Check url validity + + valid_url= urlparse(url) + # + if valid_url.scheme not in ("http", "https") or not valid_url.netloc: # if missing the correct formatting ://, urlparse.netloc will be empty + raise InvalidHTTPSpecError(f"Invalid URL: {url}. Ensure it starts with 'http://' or 'https://'") + + + + + # Initialize headers and body headers = {} body = "" From b5985bf810e55763f365e2f459870a0c6fdb54f0 Mon Sep 17 00:00:00 2001 From: sjay8 Date: Sun, 9 Mar 2025 13:53:53 -0700 Subject: [PATCH 2/8] formatting in comment --- agentic_security/http_spec.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/agentic_security/http_spec.py b/agentic_security/http_spec.py index 161955c..89adb3e 100644 --- a/agentic_security/http_spec.py +++ b/agentic_security/http_spec.py @@ -148,7 +148,8 @@ def parse_http_spec(http_spec: str) -> LLMSpec: """Parses an HTTP specification string into a LLMSpec object. Args: - http_spec (str): A string representing an HTTP specification. Returns: + http_spec (str): A string representing an HTTP specification. + Returns: LLMSpec: An object representing the parsed HTTP specification, with attributes for the method, URL, headers, and body. """ from agentic_security.core.app import get_secrets From eb14fe0f618d0a39c6cb8c5abd88f7a81c12b83e Mon Sep 17 00:00:00 2001 From: sjay8 Date: Sun, 9 Mar 2025 13:55:11 -0700 Subject: [PATCH 3/8] typo fixed --- agentic_security/http_spec.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agentic_security/http_spec.py b/agentic_security/http_spec.py index 89adb3e..8ce45a8 100644 --- a/agentic_security/http_spec.py +++ b/agentic_security/http_spec.py @@ -15,7 +15,7 @@ class Modality(Enum): FILES = 3 MIXED = 4 -# encoding the image data fro + def encode_image_base64_by_url(url: str = "https://github.com/fluidicon.png") -> str: """Encode image data to base64 from a URL""" response = httpx.get(url) @@ -40,7 +40,7 @@ class LLMSpec(BaseModel): headers: dict body: str has_files: bool = False - has_image: bool = Fa + has_image: bool = False has_audio: bool = False @classmethod From 321c3dafc029d1d3eb12682fa82045b95d39ca4d Mon Sep 17 00:00:00 2001 From: sjay8 Date: Sun, 9 Mar 2025 14:22:13 -0700 Subject: [PATCH 4/8] fixed spacing issues --- agentic_security/http_spec.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/agentic_security/http_spec.py b/agentic_security/http_spec.py index 8ce45a8..fafe68c 100644 --- a/agentic_security/http_spec.py +++ b/agentic_security/http_spec.py @@ -44,7 +44,7 @@ class LLMSpec(BaseModel): has_audio: bool = False @classmethod - # class method6 + def from_string(cls, http_spec: str): try: return parse_http_spec(http_spec) @@ -80,8 +80,6 @@ class LLMSpec(BaseModel): if self.has_audio and not encoded_audio: raise ValueError("Audio is required for this request.") - - async def probe( self, prompt: str, encoded_image: str = "", encoded_audio: str = "", files={} ) -> httpx.Response: @@ -163,16 +161,11 @@ def parse_http_spec(http_spec: str) -> LLMSpec: method, url = lines[0].split(" ")[0:2] # Check url validity - valid_url= urlparse(url) # if valid_url.scheme not in ("http", "https") or not valid_url.netloc: # if missing the correct formatting ://, urlparse.netloc will be empty raise InvalidHTTPSpecError(f"Invalid URL: {url}. Ensure it starts with 'http://' or 'https://'") - - - - # Initialize headers and body headers = {} body = "" From fa7bd104a037d851141d441b6cc68a996ae2a214 Mon Sep 17 00:00:00 2001 From: sjay8 Date: Sun, 9 Mar 2025 14:25:45 -0700 Subject: [PATCH 5/8] fixed spacing issues-2 --- agentic_security/http_spec.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agentic_security/http_spec.py b/agentic_security/http_spec.py index fafe68c..9d1e8d6 100644 --- a/agentic_security/http_spec.py +++ b/agentic_security/http_spec.py @@ -162,8 +162,8 @@ def parse_http_spec(http_spec: str) -> LLMSpec: # Check url validity valid_url= urlparse(url) - # - if valid_url.scheme not in ("http", "https") or not valid_url.netloc: # if missing the correct formatting ://, urlparse.netloc will be empty + # if missing the correct formatting ://, urlparse.netloc will be empty + if valid_url.scheme not in ("http", "https") or not valid_url.netloc: raise InvalidHTTPSpecError(f"Invalid URL: {url}. Ensure it starts with 'http://' or 'https://'") # Initialize headers and body From 4c0a57dbae195dc1ad69695a0def2cbeb868de35 Mon Sep 17 00:00:00 2001 From: sjay8 Date: Sun, 9 Mar 2025 14:28:47 -0700 Subject: [PATCH 6/8] fixed spacing issues-4 --- agentic_security/http_spec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agentic_security/http_spec.py b/agentic_security/http_spec.py index 9d1e8d6..673beff 100644 --- a/agentic_security/http_spec.py +++ b/agentic_security/http_spec.py @@ -44,7 +44,6 @@ class LLMSpec(BaseModel): has_audio: bool = False @classmethod - def from_string(cls, http_spec: str): try: return parse_http_spec(http_spec) @@ -147,6 +146,7 @@ def parse_http_spec(http_spec: str) -> LLMSpec: Args: http_spec (str): A string representing an HTTP specification. + Returns: LLMSpec: An object representing the parsed HTTP specification, with attributes for the method, URL, headers, and body. """ From 9d2885f7a666450f84f249b8e4657e8082118b3b Mon Sep 17 00:00:00 2001 From: sjay8 Date: Sun, 9 Mar 2025 14:40:35 -0700 Subject: [PATCH 7/8] spacing --- agentic_security/http_spec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agentic_security/http_spec.py b/agentic_security/http_spec.py index 673beff..d02965f 100644 --- a/agentic_security/http_spec.py +++ b/agentic_security/http_spec.py @@ -146,7 +146,7 @@ def parse_http_spec(http_spec: str) -> LLMSpec: Args: http_spec (str): A string representing an HTTP specification. - + Returns: LLMSpec: An object representing the parsed HTTP specification, with attributes for the method, URL, headers, and body. """ From 9213b64de06ac800d164c8cac607e85f9e8f710c Mon Sep 17 00:00:00 2001 From: sjay8 Date: Sun, 9 Mar 2025 14:44:42 -0700 Subject: [PATCH 8/8] spacing --- agentic_security/http_spec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agentic_security/http_spec.py b/agentic_security/http_spec.py index d02965f..de36f07 100644 --- a/agentic_security/http_spec.py +++ b/agentic_security/http_spec.py @@ -146,7 +146,7 @@ def parse_http_spec(http_spec: str) -> LLMSpec: Args: http_spec (str): A string representing an HTTP specification. - + Returns: LLMSpec: An object representing the parsed HTTP specification, with attributes for the method, URL, headers, and body. """