Skip to content

Validate safety identifier endpoint hosts - #83

Open
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/validate-safety-endpoint-host
Open

Validate safety identifier endpoint hosts#83
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/validate-safety-endpoint-host

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jul 26, 2026

Copy link
Copy Markdown

Summary

  • parse custom base URLs before deciding whether the safety identifier is supported
  • accept the primary API hostname and anchored regional subdomains
  • reject suffix-domain, userinfo, and missing-boundary lookalikes
  • add regression coverage for primary, European, and US regional endpoints

Why

The previous substring check treated any URL containing api.openai.com as an official endpoint. An exact-host replacement fixed those lookalikes but excluded official regional endpoints such as eu.api.openai.com.

Matching the primary hostname or an anchored subdomain preserves regional endpoint support without accepting attacker-controlled suffix domains.

Testing

  • uv run ruff check
  • uv run mypy src/guardrails/utils/safety_identifier.py
  • uv run pyright src/guardrails/utils/safety_identifier.py
  • uv run pytest -q (441 passed)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b70d0713aa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

base_url_str = str(base_url)
# Only official OpenAI API endpoints support safety_identifier
return "api.openai.com" in base_url_str
return urlparse(str(base_url)).hostname == "api.openai.com"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recognize official regional API hosts

When a client uses an official regional data-residency URL such as https://eu.api.openai.com/v1, the parsed hostname is eu.api.openai.com, so this exact comparison returns false. The previous substring check accepted these regional OpenAI hosts; this change therefore stops sending safety_identifier for those clients even though they are still using the official OpenAI API. Recognize the supported regional hostnames while continuing to reject lookalike domains.

Useful? React with 👍 / 👎.

@fallintoplace
fallintoplace force-pushed the fix/validate-safety-endpoint-host branch from b70d071 to 7d6e80a Compare July 26, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant