Skip to content

Commit 682fd47

Browse files
committed
fix: reject non-finite AI lane config values
1 parent 44d141d commit 682fd47

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎posthog/client.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
from contextlib import contextmanager
66
import logging
7+
import math
78
import os
89
import sys
910
import threading
@@ -233,13 +234,18 @@ def _get_atexit_deadline() -> float:
233234
def _positive_config_value(
234235
name: str, value, *, integer: bool = False, maximum: Optional[int] = None
235236
):
236-
"""Return ``value`` if it is positive and no larger than ``maximum``.
237+
"""Return ``value`` if it is finite, positive and no larger than ``maximum``.
237238
238239
Bad lane config is a programming error, so it raises instead of falling
239240
back to a default.
240241
"""
241242
allowed = (int,) if integer else (int, float)
242-
if isinstance(value, bool) or not isinstance(value, allowed) or value <= 0:
243+
if (
244+
isinstance(value, bool)
245+
or not isinstance(value, allowed)
246+
or not math.isfinite(value)
247+
or value <= 0
248+
):
243249
kind = "integer" if integer else "number"
244250
raise ValueError(f"{name} must be a positive {kind}, got {value!r}")
245251
if maximum is not None and value > maximum:

‎posthog/test/test_ai_capture_lane.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ def test_ai_lane_consumers_use_ai_config(
287287
("queue_size_negative", "capture_ai_max_queue_size", -1),
288288
("queue_size_string", "capture_ai_max_queue_size", "100"),
289289
("timeout_zero", "capture_ai_timeout", 0),
290+
("timeout_nan", "capture_ai_timeout", float("nan")),
291+
("timeout_inf", "capture_ai_timeout", float("inf")),
290292
("compression_unknown", "capture_ai_compression", "br"),
291293
]
292294
)

0 commit comments

Comments
 (0)