Repository navigation
Pin the TypeSafe Pareto API key to allowlisted hosts - #16
Merged
Merged
Conversation
urllib kept Authorization across cross-host redirects, and a base URL override could aim the key at any host. Reject other hosts before a request and refuse redirects that leave the allowlist. Tools script only; not a package release. Co-authored-by: Jason <jkbennitt@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
urllib.requestkeepsAuthorizationon cross-host redirects, and--base-url/TYPESAFE_BASE_URLcould aim the TypeSafe API key at any host. The key is now pinned toapi.typesafe.ai: other base URLs are rejected before a request, and redirects whose host is off that allowlist are refused before a second request is opened.This is not a major production PR. It changes the
tools/typesafe-paretoscript and its unit tests only. No PackageId, version, CHANGELOG, or NuGet release.What broke in live use
_http_system_onesentAuthorization: Bearer <TYPESAFE_API_KEY>throughurllib.request.urlopen. On Python 3.12,HTTPRedirectHandler.redirect_requestcopies those request headers onto the redirected request, including whenLocationpoints at another host.resolve_base_urlalso returned--base-url(andrun_pass(base_url=...)) orTYPESAFE_BASE_URLwith no host check, so the same key could be pointed at an arbitrary origin. The default remainshttps://api.typesafe.ai.How you checked
tools/typesafe-pareto/test_score_pareto.py(no sockets): the allowlisted defaulthttps://api.typesafe.aiis accepted and a scripted 200 receivesAuthorizationonly there; disallowed--base-url/TYPESAFE_BASE_URLvalues raiseTypeSafeConfigErrorbeforeRequest,build_opener, or an injected post; a scripted cross-host 302 raises and the bearer token is recorded only forapi.typesafe.ai.python3 -m unittest tools/typesafe-pareto/test_score_pareto.py -v(22 tests) andpython3 tools/typesafe-pareto/score_pareto.py --smoke --force-mock --no-metrics.What stayed unchanged
--force-mockwhen the base URL is allowlisted.TypeSafeClientwith the same arguments whentypesafe-sdkis installed. A base URL whose host is off the allowlist is rejected before that client is constructed. SDK-internal redirect behavior is unchanged.Checklist
dotnet test Unsga3.slnx -c Release— not run; library code is unchangedTest plan
python3 -m unittest tools/typesafe-pareto/test_score_pareto.py -vpython3 tools/typesafe-pareto/score_pareto.py --smoke --force-mock --no-metricspython3 tools/typesafe-pareto/score_pareto.py --smoke --force-mock --no-metrics --base-url https://evil.exampleexits 2 and does not write metrics