JSON Pointer lookup accepts malformed tilde escapes in object keys

Ouverte
#448 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
47/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
python

Piste de recherche

Start with Resolver.lookup and the mapping branch that decodes ~1 and ~0; compare its behavior with RFC 6901 section 3. Check the existing resolution exception types and tests for Resolver.lookup and Resource.pointer. Done means malformed escapes such as ~2 and trailing ~ fail resolution while correctly escaped forms such as ~02 still succeed; the issue leaves the exception choice open.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Resolver.lookup accepts malformed JSON Pointer tilde escapes when a matching object key exists. For example, ~2 and a trailing ~ are treated as literal key text rather than an invalid pointer.

from referencing import Registry
from referencing.jsonschema import DRAFT202012

resource = DRAFT202012.create_resource({
    "$defs": {"~2": {"type": "integer"}, "~": {"type": "string"}},
})
resolver = Registry().resolver_with_root(resource)

print(resolver.lookup("#/$defs/~2").contents)   # {'type': 'integer'}
print(resolver.lookup("#/$defs/~").contents)    # {'type': 'string'}
# The correctly escaped forms work too:
print(resolver.lookup("#/$defs/~02").contents)  # {'type': 'integer'}
print(resolver.lookup("#/$defs/~0").contents)   # {'type': 'string'}

RFC 6901 section 3 permits only ~0 and ~1 as escapes and defines invalid syntax as an error condition. Section 7 leaves the error-handling mechanism to the application. I would expect the first two lookups to fail resolution; the correctly escaped forms should continue to succeed.

Reproduced on main at 45e3c7f0b8191f6f433417d26a59e1e2857f0fcb, Python 3.13.17, macOS ARM64, attrs 26.1.0 and rpds-py 2026.6.3. A local matrix checked six valid and six invalid fragments through both Resolver.lookup and Resource.pointer: all valid controls resolved, but all invalid fragments resolved too. This includes a~b, ~0~ and percent-encoded %7E2; ~01 and ~00 were valid controls to preserve decoding order.

The existing suite, including its pinned referencing-suite submodule, passed locally: 503 passed, 132 xfailed and 406 subtests passed. These are baseline results, not tests of a fix.

The mapping branch currently replaces ~1 and ~0 without validating the token first. I checked #387 and #427: those concern array indices; #444 concerns traversal into scalar values. This report concerns object-key escape syntax and does not propose taking over those patches.

Is rejecting malformed escapes the intended behavior, and should it use an existing resolution exception or a distinct syntax error? I have not prepared a production patch pending that API/compatibility decision. This was found through local code inspection, not a production incident; no security impact is claimed.

OpenAI Codex (GPT-6) assisted with investigation, local reproduction and drafting.

Langage dominant
Python
Étoiles
56
Forks
55
Merge moyen
6 j 7 h
PR mergées (30 j)
5

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de python-jsonschema/referencing

Toutes les issues de python-jsonschema/referencing

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.