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

Aperta
#1,533 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Java
Stelle
1.1k
Fork
655
Merge medio
4h 54m
PR unite (30g)
10

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di spring-cloud/spring-cloud-function

Tutte le issue di spring-cloud/spring-cloud-function

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.