Make JsonMasker load mask keys from jars and be thread-safe

Offen
#1,533 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
58/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
java
Bereich
backend

Rechercherichtung

Start in JsonMasker: the singleton INSTANCE() double-checked locking, the INSTANCE(Set) key loading via Files.readAllLines(Path.of(uri)), and mask(..) are all in the same class. Change resource loading to URL.openStream(), replace the TreeSet with a concurrent set, skip blank lines, and handle non-JSON byte[] and nested arrays in mask(..). Add tests that load META-INF/mask.keys from a jar plus cases for blank keys, byte[] input and arrays inside arrays; done when the existing directory-based tests still pass alongside the new ones.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

5.0.x backport enhancement

JsonMasker loads the keys to mask from META-INF/mask.keys resources using Files.readAllLines(Path.of(uri)). For a resource inside a jar (for example a fat jar deployed to AWS Lambda) the jar: URI cannot be converted to a Path unless a zip file system is already open, so loading fails, a warning is logged and the key set stays empty. As a result nothing is masked in packaged deployments. The existing tests do not notice because their mask.keys is loaded from a directory.

Related problems in the same class:

  • the singleton field is not volatile, so the double-checked locking in INSTANCE() does not guarantee safe publication
  • the set of keys is a plain TreeSet that is modified by INSTANCE(Set) while other threads may be reading it in mask(..)
  • a blank line in mask.keys registers an empty string as a key
  • mask(..) throws ClassCastException for a byte[] input that is not JSON
  • an array nested directly inside an array is not searched for keys to mask

Proposed change:

  • read the resources with URL.openStream() so that they also work from jars
  • create the instance with a holder class and keep the keys in a concurrent set
  • skip blank entries
  • return the text for non-JSON byte[] input
  • mask keys in nested arrays
  • add tests for loading keys from a jar and for the cases above

Public method signatures stay the same.

Vorherrschende Sprache
Java
Sterne
1.1k
Forks
655
Ø Merge
4 Std. 54 Min.
Gemergte PRs (30 T.)
10

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus spring-cloud/spring-cloud-function

Alle Issues in spring-cloud/spring-cloud-function

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

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