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

Đang mở
#1,533 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
58/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Java
Star
1.1k
Fork
655
Merge trung bình
4 giờ 54 phút
Pull request đã merge (30 ngày)
10

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của spring-cloud/spring-cloud-function

Tất cả issue của spring-cloud/spring-cloud-function

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.