Skip to content

Commit 47c7f4d

Browse files
Reject control characters in polling operation names
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 4be74e5 commit 47c7f4d

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

hyperbrowser/client/polling.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def _validate_operation_name(operation_name: str) -> None:
3131
raise HyperbrowserError("operation_name must be a string")
3232
if not operation_name.strip():
3333
raise HyperbrowserError("operation_name must not be empty")
34+
if any(
35+
ord(character) < 32 or ord(character) == 127 for character in operation_name
36+
):
37+
raise HyperbrowserError("operation_name must not contain control characters")
3438

3539

3640
def _validate_retry_config(

tests/test_polling.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,16 @@ def test_polling_helpers_validate_retry_and_interval_configuration():
667667
retry_delay_seconds=0,
668668
)
669669

670+
with pytest.raises(
671+
HyperbrowserError, match="operation_name must not contain control characters"
672+
):
673+
retry_operation(
674+
operation_name="invalid\nretry",
675+
operation=lambda: "ok",
676+
max_attempts=1,
677+
retry_delay_seconds=0,
678+
)
679+
670680
with pytest.raises(HyperbrowserError, match="max_attempts must be an integer"):
671681
retry_operation(
672682
operation_name="invalid-retry-type",
@@ -804,5 +814,16 @@ async def validate_async_operation_name() -> None:
804814
poll_interval_seconds=0.1,
805815
max_wait_seconds=1.0,
806816
)
817+
with pytest.raises(
818+
HyperbrowserError,
819+
match="operation_name must not contain control characters",
820+
):
821+
await poll_until_terminal_status_async(
822+
operation_name="invalid\tasync",
823+
get_status=lambda: asyncio.sleep(0, result="completed"),
824+
is_terminal_status=lambda value: value == "completed",
825+
poll_interval_seconds=0.1,
826+
max_wait_seconds=1.0,
827+
)
807828

808829
asyncio.run(validate_async_operation_name())

0 commit comments

Comments
 (0)