Skip to content

Commit

Permalink
feat: add protections in masks with user defined content
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienaury committed Sep 16, 2024
1 parent 93bb69a commit ff600ee
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewMask(value model.Entry, tmpl tmpl.FuncMap, seed int64, seedField string)
temp, err := template.NewEngine(tmplstr, tmpl, seed, seedField)
return MaskEngine{value, temp}, err
}
return MaskEngine{value, nil}, nil
return MaskEngine{model.CleanTypes(value), nil}, nil
}

// MaskContext add the field
Expand Down
2 changes: 1 addition & 1 deletion pkg/addtransient/add-transient.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewMask(value model.Entry, tmpl tmpl.FuncMap, seed int64, seedField string)
temp, err := template.NewEngine(tmplstr, tmpl, seed, seedField)
return MaskEngine{value, temp}, err
}
return MaskEngine{value, nil}, nil
return MaskEngine{model.CleanTypes(value), nil}, nil
}

// MaskContext add the field
Expand Down
2 changes: 1 addition & 1 deletion pkg/hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type MaskEngine struct {
// NewMaskSeeded create a MaskRandomList with a seed
func NewMask(list []model.Entry) MaskEngine {
// nolint: gosec
return MaskEngine{list}
return MaskEngine{model.CleanTypes(list).([]model.Entry)}
}

// Mask choose a mask value by hash
Expand Down
11 changes: 7 additions & 4 deletions pkg/model/ordered_dict.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,18 @@ func CleanTypes(inter interface{}) interface{} {
dict.Set(key, CleanTypes(value))
}
return dict
case []Entry:
tab := make([]Entry, 0, len(typedInter))
for _, item := range typedInter {
tab = append(tab, CleanTypes(item))
}
return tab
case []interface{}:
tab := []Entry{}

tab := make([]Entry, 0, len(typedInter))
for _, item := range typedInter {
tab = append(tab, CleanTypes(item))
}

return tab

case json.Number:

resFloat64, err := typedInter.Float64()
Expand Down
2 changes: 1 addition & 1 deletion pkg/randomlist/randomlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type MaskEngine struct {
// NewMaskSeeded create a MaskRandomList with a seed
func NewMask(list []model.Entry, seed int64, seeder model.Seeder) MaskEngine {
// nolint: gosec
return MaskEngine{rand.New(rand.NewSource(seed)), seeder, list}
return MaskEngine{rand.New(rand.NewSource(seed)), seeder, model.CleanTypes(list).([]model.Entry)}
}

// Mask choose a mask value randomly
Expand Down

0 comments on commit ff600ee

Please sign in to comment.