File tree Expand file tree Collapse file tree 5 files changed +27
-1
lines changed Expand file tree Collapse file tree 5 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ Types of changes
14
14
- ` Fixed ` for any bug fixes.
15
15
- ` Security ` in case of vulnerabilities.
16
16
17
+ ## [ 1.30.1]
18
+
19
+ - ` Fixed ` mask ` command ` split command line on space protected by quote
20
+
17
21
## [ 1.30.0]
18
22
19
23
- ` Added ` mask ` partitions ` to handle fields containing different types of values by applying distinct transformations
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ require (
52
52
github.com/labstack/gommon v0.4.2 // indirect
53
53
github.com/mailru/easyjson v0.7.7 // indirect
54
54
github.com/mattn/go-colorable v0.1.13 // indirect
55
+ github.com/mattn/go-shellwords v1.0.12
55
56
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
56
57
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
57
58
github.com/mitchellh/copystructure v1.2.0 // indirect
Original file line number Diff line number Diff line change @@ -98,6 +98,8 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
98
98
github.com/mattn/go-isatty v0.0.19 /go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y =
99
99
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY =
100
100
github.com/mattn/go-isatty v0.0.20 /go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y =
101
+ github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk =
102
+ github.com/mattn/go-shellwords v1.0.12 /go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y =
101
103
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 h1:AMFGa4R4MiIpspGNG7Z948v4n35fFGB3RR3G/ry4FWs =
102
104
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 /go.mod h1:mC1jAcsrzbxHt8iiaC+zU4b1ylILSosueou12R++wfY =
103
105
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 h1:+n/aFZefKZp7spd8DFdX7uMikMLXX4oubIzJF4kv/wI =
Original file line number Diff line number Diff line change 18
18
package command
19
19
20
20
import (
21
+ "fmt"
21
22
"os/exec"
22
23
"strings"
23
24
24
25
"github.com/cgi-fr/pimo/pkg/model"
25
26
"github.com/rs/zerolog/log"
27
+
28
+ "github.com/mattn/go-shellwords"
26
29
)
27
30
28
31
// MaskEngine implements MaskEngine with a console command
@@ -38,7 +41,13 @@ func NewMask(cmd string) MaskEngine {
38
41
// Mask delegate mask algorithm to an external program
39
42
func (cme MaskEngine ) Mask (e model.Entry , context ... model.Dictionary ) (model.Entry , error ) {
40
43
log .Info ().Msg ("Mask command" )
41
- splitCommand := strings .Split (cme .Cmd , " " )
44
+ line := cme .Cmd
45
+ parser := shellwords .NewParser ()
46
+ parser .ParseEnv = true
47
+ splitCommand , err := parser .Parse (line )
48
+ if err != nil {
49
+ return "" , fmt .Errorf ("failed to parse command %w" , err )
50
+ }
42
51
/* #nosec */
43
52
out , err := exec .Command (splitCommand [0 ], splitCommand [1 :]... ).Output ()
44
53
Original file line number Diff line number Diff line change @@ -34,6 +34,16 @@ func TestMaskingShouldReplaceSensitiveValueByCommand(t *testing.T) {
34
34
assert .Equal (t , waited , result , "should be Toto" )
35
35
}
36
36
37
+ func TestMaskingShouldPreserveSpaceInQuote (t * testing.T ) {
38
+ nameProgramMasking := NewMask ("echo \" Toto \" " )
39
+ data := "Benjamin"
40
+ result , err := nameProgramMasking .Mask (data )
41
+ assert .Equal (t , nil , err , "error should be nil" )
42
+ waited := " Toto "
43
+ assert .NotEqual (t , data , result , "should be masked" )
44
+ assert .Equal (t , waited , result , "should be Toto with space" )
45
+ }
46
+
37
47
func TestMaskingShouldReturnAnErrorInCaseOfWrongCommand (t * testing.T ) {
38
48
nameCommandMasking := NewMask ("WrongCommand" )
39
49
You can’t perform that action at this time.
0 commit comments