php / php/php-src

Add `max_object_properties` parameter for `json_decode()`

Offen
#10,376 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Extension: json Feature Status: Verified
Vorherrschende Sprache
C
Sterne
40.4k
Forks
8.1k
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
96

Beschreibung

Description

Currently, json_decode() is vulnerable to HashTable supercolliding, when integers are used as property names in assoc mode, or perhaps when strings with some known hashes are used. This can be trivially exploited to cause major performance issues in applications which accept JSON payloads from a client.

While this is obviously a tough issue to solve globally, I think allowing users of json_decode() to limit the max number of object properties would mostly eliminate the problem for JSON handling, since most use cases should know or be able to predict what the max reasonable size of an object should be. I think this should probably be fairly easy to implement.

A precedent for this does exist: max_input_vars was implemented to mitigate HashDoS for query parameters over a decade ago, so I don't think this is a crazy idea.

Disclaimer: I did already report a security issue for this and was told to create a feature request, so here it is.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne beim Einstiegspunkt json_decode() und prüfe das im Issue erwähnte Präzedenzbeispiel max_input_vars. Lege fest, wie ein Parameter max_object_properties dekodierte Objekte begrenzen soll, einschließlich seiner Wechselwirkung mit dem assoc-Modus, und füge Testabdeckung hinzu, die zeigt, dass zu große Objekte wie vorgesehen abgelehnt oder begrenzt werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
c, php
Bereich
security
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.