Require the API schema parameter to be a URL - #1445
Merged
Merged
Conversation
The lint endpoint documents schema as a URL, but nothing enforced it and fetch_schema falls through to the filesystem for anything that is not http(s). An unauthenticated caller could therefore have the server open its own files, and distinguish an existing path from a missing one by the error returned. Only http and https are accepted now, and every rejection looks the same.
📖 Docs previewPreview site: https://brave-water-0cee36e03-1445.westeurope.7.azurestaticapps.net Changed pages (most-changed first):
|
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
The
/lintendpoint of thedatacontract apiserver documents itsschemaquery parameter as "This must be a URL", but nothing enforced it.fetch_schematreats anything that is nothttp(s)://as a filesystem path, so an unauthenticated caller could make the server read its own files.Verified against a running server before the fix:
?schema=/tmp/local-schema.json"result":"passed"?schema=/etc/passwdExpecting value: line 1) — proof the read happened?schema=/nonexistent/pathThe file ... does not exist— a file-existence oracleOnly
http://andhttps://are accepted now, and every rejection returns the same 422, so nothing can be learned about the filesystem from the response.After the fix, same three requests:
A real URL and the no-schema case both still work.
How it was found
Two of the three open CodeQL alerts —
py/path-injectionatlint/schema.py:50and:60. They read as false positives at first, since the same function is reached from the CLI's--json-schema, where the operator supplies the path deliberately. Following the call graph toapi.pyshowed a second caller where the value is remote and unauthenticated, which is what makes them real.The third alert is a false positive
py/unsafe-deserializationatlint/resolve.py:405flagsyaml.load(data_contract_str, Loader=_SafeLoaderNoTimestamp). That loader is ayaml.SafeLoadersubclass which only drops the timestamp implicit resolver so dates stay strings. CodeQL does not track the subclass. No code change; it should be dismissed as a false positive rather than worked around.Still open, deliberately not in this PR
The URL branch calls
requests.geton a caller-supplied URL with no restriction, so the server can be made to fetch arbitrary hosts, including link-local metadata endpoints. Closing that needs a policy decision — an allowlist, or blocking private ranges — rather than a one-line validation, so it is worth deciding separately.Testing
Four tests: a local path rejected, a missing path rejected identically to an existing one, a relative path rejected, and an
httpURL still accepted.