check bitwarden itemid format (#4508)

This commit is contained in:
LawyZheng
2026-01-22 01:42:42 +08:00
committed by GitHub
parent 649a246772
commit b9cbabe634
2 changed files with 16 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ from skyvern.forge.sdk.schemas.credentials import (
SecretCredential,
)
from skyvern.forge.sdk.services.credentials import parse_totp_secret
from skyvern.utils.strings import is_uuid
LOG = structlog.get_logger()
BITWARDEN_SERVER_BASE_URL = f"{settings.BITWARDEN_SERVER}:{settings.BITWARDEN_SERVER_PORT or 8002}"
@@ -223,6 +224,9 @@ class BitwardenService:
if not bw_organization_id and bw_collection_ids and collection_id not in bw_collection_ids:
raise BitwardenAccessDeniedError()
if item_id and not is_uuid(item_id):
raise BitwardenGetItemError(f"Invalid item ID: {item_id}. Check if the item ID is correct")
for i in range(max_retries):
# FIXME: just simply double the timeout for the second try. maybe a better backoff policy when needed
timeout = (i + 1) * timeout
@@ -698,6 +702,9 @@ class BitwardenService:
"""
Get the credit card data from the Bitwarden CLI.
"""
if not is_uuid(item_id):
raise BitwardenGetItemError(f"Invalid item ID: {item_id}. Check if the item ID is correct")
try:
async with asyncio.timeout(settings.BITWARDEN_TIMEOUT_SECONDS):
return await BitwardenService._get_credit_card_data(

View File

@@ -1,6 +1,7 @@
import os
import random
import string
import uuid
RANDOM_STRING_POOL = string.ascii_letters + string.digits
@@ -9,3 +10,11 @@ def generate_random_string(length: int = 5) -> str:
# Use the os.urandom(16) as the seed
random.seed(os.urandom(16))
return "".join(random.choices(RANDOM_STRING_POOL, k=length))
def is_uuid(string: str) -> bool:
try:
uuid.UUID(string)
return True
except ValueError:
return False