Commit c93c666
fix(nvidia): use proper URL parsing instead of substring check for hostname validation (#5777)
## Summary
- Replaces substring-based hostname check in `_is_nvidia_hosted()` with
proper URL parsing via `urlparse()` to prevent bypass via crafted URLs
(e.g. `https://evil.com/integrate.api.nvidia.com`)
- Extracts the hostname constant into `_NVIDIA_HOSTED_HOSTNAME` for
clarity
- Addresses CWE-20 (Improper Input Validation)
Fixes: https://github.com/ogx-ai/ogx/security/code-scanning/55
## Test plan
- [ ] Verify `_is_nvidia_hosted()` returns `True` for
`https://integrate.api.nvidia.com/v1`
- [ ] Verify `_is_nvidia_hosted()` returns `False` for
`https://evil.com/integrate.api.nvidia.com`
- [ ] Run unit tests: `uv run pytest tests/unit/ -x --tb=short`
- [ ] Run pre-commit checks: `uv run pre-commit run --all-files`
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Signed-off-by: Sébastien Han <seb@redhat.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 2a4be91 commit c93c666
1 file changed
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
| 11 | + | |
| 12 | + | |
9 | 13 | | |
10 | 14 | | |
11 | | - | |
| 15 | + | |
| 16 | + | |
0 commit comments