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

未关闭
#1,533 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
backend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Java
星标
1.1k
派生
655
平均合并
4 小时 54 分钟
30 天内合并 PR
10

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

spring-cloud/spring-cloud-function 的其他 Issue

查看 spring-cloud/spring-cloud-function 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。