mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-20 15:24:40 +00:00
fix(image-gen): guard local provider inputs against credential reads
This commit is contained in:
parent
203b5d4cea
commit
587be5b5b4
4 changed files with 44 additions and 0 deletions
|
|
@ -147,6 +147,16 @@ def _load_image_bytes(ref: str) -> Tuple[bytes, str]:
|
|||
ext = header.split("image/", 1)[1].split(";", 1)[0] or "png"
|
||||
return base64.b64decode(b64), f"image.{ext}"
|
||||
# Local file path.
|
||||
try:
|
||||
from agent.file_safety import get_read_block_error
|
||||
|
||||
blocked = get_read_block_error(ref)
|
||||
if blocked:
|
||||
raise ValueError(blocked)
|
||||
except ValueError:
|
||||
raise
|
||||
except Exception as exc: # noqa: BLE001 - preserve existing local-file behavior
|
||||
logger.debug("OpenAI image input read guard unavailable: %s", exc)
|
||||
with open(ref, "rb") as fh:
|
||||
data = fh.read()
|
||||
name = os.path.basename(ref) or "image.png"
|
||||
|
|
|
|||
|
|
@ -97,6 +97,16 @@ def _to_image_url_part(ref: str) -> Optional[str]:
|
|||
if ref.startswith(("http://", "https://", "data:")):
|
||||
return ref
|
||||
path = Path(ref)
|
||||
try:
|
||||
from agent.file_safety import get_read_block_error
|
||||
|
||||
blocked = get_read_block_error(ref)
|
||||
if blocked:
|
||||
raise ValueError(blocked)
|
||||
except ValueError:
|
||||
raise
|
||||
except Exception as exc: # noqa: BLE001 - keep local image refs best-effort
|
||||
logger.debug("OpenRouter image input read guard unavailable: %s", exc)
|
||||
try:
|
||||
raw = path.read_bytes()
|
||||
except OSError as exc:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue