Resolve an API URL preference against the allowlist. - User preference set and allowed: return it. - User preference set but rejected: log a warning and return '' WITHOUT falling back to the admin default. Silent substitution hides the rejection and routes the user's reques
(pref_name, config_default)
| 286 | |
| 287 | |
| 288 | def _resolve_pref_url(pref_name, config_default): |
| 289 | """ |
| 290 | Resolve an API URL preference against the allowlist. |
| 291 | |
| 292 | - User preference set and allowed: return it. |
| 293 | - User preference set but rejected: log a warning and return '' |
| 294 | WITHOUT falling back to the admin default. Silent substitution |
| 295 | hides the rejection and routes the user's request to a |
| 296 | different provider (issue #9936). |
| 297 | - No user preference: return the admin's trusted config URL. |
| 298 | """ |
| 299 | pref_url = _get_preference_value(pref_name) |
| 300 | if pref_url: |
| 301 | if validate_api_url(pref_url): |
| 302 | return pref_url |
| 303 | try: |
| 304 | from flask import current_app |
| 305 | current_app.logger.warning( |
| 306 | "LLM API URL preference '%s'=%r is not in " |
| 307 | "ALLOWED_LLM_API_URLS; ignoring. Add it to the " |
| 308 | "allowlist in config_local.py to permit this URL.", |
| 309 | pref_name, pref_url |
| 310 | ) |
| 311 | except Exception: |
| 312 | pass |
| 313 | return '' |
| 314 | return config_default or '' |
| 315 | |
| 316 | |
| 317 | def is_pref_api_url_rejected(pref_name): |
no test coverage detected