Skip to content

Commit 4b24cb1

Browse files
adrienauryCopilot
andauthored
fix(hashincsv): should not be salted by jsonpath (#434)
* fix(hashincsv): do not salt seed with jsonpath * fix: grammatical errors in comment Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: remove unused code Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix(hashincsv): should not be salted by jsonpath * docs: update changelog --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent cd1752d commit 4b24cb1

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Types of changes
1414
- `Fixed` for any bug fixes.
1515
- `Security` in case of vulnerabilities.
1616

17+
## [1.31.3]
18+
19+
- `Fixed` `hashInCSV` consistency when used in different jsonpath
20+
1721
## [1.31.2]
1822

1923
- `Fixed` mask `pipe` with `injectRoot` option

pkg/hashcsv/hashcsv.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,7 @@ func (mrl MaskEngine) GenIdentifierIfNeeded(obj model.Dictionary, e model.Entry,
166166
func Factory(conf model.MaskFactoryConfiguration) (model.MaskEngine, bool, error) {
167167
seeder := model.NewSeeder(conf.Masking.Seed.Field, conf.Seed)
168168

169-
// set differents seeds for differents jsonpath
170-
h := fnv.New64a()
171-
h.Write([]byte(conf.Masking.Selector.Jsonpath))
172-
conf.Seed += int64(h.Sum64()) //nolint:gosec
169+
// do not set different seeds for different jsonpaths
173170

174171
if len(conf.Masking.Mask.HashInCSV.URI) != 0 {
175172
mask, err := NewMask(conf.Masking.Mask.HashInCSV, conf.Seed, seeder)

test/suites/masking_hash_in_csv.yml

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,45 @@ testcases:
240240
echo -e '{"person":1}\n{"person":2}\n{"person":3}\n{"person":2}\n{"person":1}\n{"person":3}' | pimo | head -c -1 | tr '\n' ' '
241241
assertions:
242242
- result.code ShouldEqual 0
243-
- result.systemout ShouldEqual {"person":"4687448"} {"person":"6918459"} {"person":"815901"} {"person":"6918459"} {"person":"4687448"} {"person":"815901"}
243+
- result.systemout ShouldEqual {"person":"11441486"} {"person":"5092990"} {"person":"12077293"} {"person":"5092990"} {"person":"11441486"} {"person":"12077293"}
244244
- result.systemerr ShouldBeEmpty
245245
246+
- name: different jsonpath generate same identifier
247+
steps:
248+
- script: rm -f masking.yml
249+
- script: |-
250+
cat > masking.yml <<EOF
251+
version: "1"
252+
seed: 42
253+
masking:
254+
- selector:
255+
jsonpath: "person1"
256+
masks:
257+
- hashInCSV:
258+
uri: "file://../persons.csv"
259+
header: true
260+
identifier:
261+
field: "id"
262+
domain: "0123456789"
263+
resistance: 1000
264+
- template: "{{ .person1.id }}"
265+
- selector:
266+
jsonpath: "person2"
267+
masks:
268+
- hashInCSV:
269+
uri: "file://../persons.csv"
270+
header: true
271+
identifier:
272+
field: "id"
273+
domain: "0123456789"
274+
resistance: 1000
275+
- template: "{{ .person2.id }}"
276+
EOF
277+
- script: |-
278+
echo -e '{"person1":1,"person2":1}' | pimo
279+
assertions:
280+
- result.code ShouldEqual 0
281+
- result.systemout ShouldEqual {"person1":"11441486","person2":"11441486"}
282+
- result.systemerr ShouldBeEmpty
283+
284+

0 commit comments

Comments
 (0)