feat(anchors): validate stellar.toml schema version before use - #832
Open
woahwhattheheck wants to merge 2 commits into
Open
feat(anchors): validate stellar.toml schema version before use#832woahwhattheheck wants to merge 2 commits into
woahwhattheheck wants to merge 2 commits into
Conversation
A future SEP-1 schema may move or re-type fields; parsing it with the current logic yields plausible but wrong data instead of an error. The parser now checks VERSION first, immediately after a successful parse, and throws UnsupportedTomlVersionError naming the version it found. A document declaring no VERSION is still accepted: SEP-1 does not require the field and many published files omit it.
4 tasks
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.
Closes #779.
StellarTomlParserparsedstellar.tomlwithout ever readingVERSION. Adocument written against a future SEP-1 schema — where a field has moved or
changed type — parses "successfully" and yields plausible but wrong data, with
nothing to signal it. The parser now gates on the declared version, as the
first validation after a successful parse.
Changes
src/anchors/StellarTomlParser.ts:SUPPORTED_TOML_VERSIONS— exported,["2.0", "2.1"].UnsupportedTomlVersionError— carriesversion(exactly as it appeared),domain, andsupportedVersions.toml.parsesucceeds, before the metadataobject is assembled or cached.
Version comparison
Versions are compared as
major.minor, because the same version is writtenseveral ways in the wild:
VERSION = "2.0"2.0VERSION = "2.0.0"2.0VERSION = "2"2.0VERSION = 2.022.0The unquoted form matters: TOML reads
2.0as a float, so a strict stringcomparison would reject a perfectly ordinary document.
A malformed minor is not rounded down —
"2.x"is rejected rather thanbeing read as
"2.0", so a typo can't quietly select the wrong schema.A document with no VERSION is still accepted
SEP-1 does not require the field and many published
stellar.tomlfiles omitit, so treating absence as a failure would reject valid anchors. Only a
declared-and-unsupported version fails.
Rejected documents are not cached
The throw happens before the cache write, so a rejected domain leaves no entry
behind and a later corrected document is fetched normally rather than being
masked by a poisoned cache. There's a test for this.
Validation
npx vitest run test/stellarTomlParser.version.test.ts— 13/13 passing.Covers the supported forms above, absent VERSION, older (
1.9) and future(
3.0) versions, malformed2.x, the error's fields and message, and thecache behaviour. Network-free:
fetchis stubbed.npx tsc --noEmitreports 210 errors on this branch and 210 on unmodifiedmain— identical, with none insrc/anchors/StellarTomlParser.ts.That baseline is pre-existing and unrelated to this change.