Skip to content

Commit 254be3c

Browse files
Tighten header env parsing type checks
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 2e15239 commit 254be3c

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

hyperbrowser/header_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import Dict, Mapping, Optional
2+
from typing import Dict, Mapping, Optional, cast
33

44
from .exceptions import HyperbrowserError
55

@@ -43,8 +43,12 @@ def parse_headers_env_json(raw_headers: Optional[str]) -> Optional[Dict[str, str
4343
raise HyperbrowserError(
4444
"HYPERBROWSER_HEADERS must be valid JSON object"
4545
) from exc
46+
if not isinstance(parsed_headers, Mapping):
47+
raise HyperbrowserError(
48+
"HYPERBROWSER_HEADERS must be a JSON object of string pairs"
49+
)
4650
return normalize_headers(
47-
parsed_headers, # type: ignore[arg-type]
51+
cast(Mapping[str, str], parsed_headers),
4852
mapping_error_message="HYPERBROWSER_HEADERS must be a JSON object of string pairs",
4953
pair_error_message="HYPERBROWSER_HEADERS must be a JSON object of string pairs",
5054
)

0 commit comments

Comments
 (0)