mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
plugins/logs: Update mechanism to escape field paths (#4756)
Earlier the paths to the field to perform an upsert or remove operation on were escaped using Go's url.QueryEscape method. This results in incorrect behavior when the paths contain a reserved character like ":". This change updates to using url.PathEscape instead to escape the input and result paths. Fixes: #4717 Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
This commit is contained in:
@@ -70,12 +70,12 @@ func newMaskRule(path string, opts ...maskRuleOption) (*maskRule, error) {
|
||||
|
||||
escapedParts := make([]string, len(parts))
|
||||
for i := range parts {
|
||||
_, err := url.QueryUnescape(parts[i])
|
||||
_, err := url.PathUnescape(parts[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
escapedParts[i] = url.QueryEscape(parts[i])
|
||||
escapedParts[i] = url.PathEscape(parts[i])
|
||||
}
|
||||
|
||||
modifyFullObj := false
|
||||
|
||||
@@ -541,6 +541,25 @@ func TestMaskRuleMask(t *testing.T) {
|
||||
event: `{"input": {"foo": [{"bar": 1, "baz": 2}]}}`,
|
||||
exp: `{"input": {"foo": [{"baz": 2}]}, "erased": ["/input/foo/0/bar"]}`,
|
||||
},
|
||||
{
|
||||
note: "erase input: special character in path",
|
||||
ptr: &maskRule{
|
||||
OP: maskOPRemove,
|
||||
Path: "/input/:path",
|
||||
},
|
||||
event: `{"input": {"bar": 1, ":path": "token"}}`,
|
||||
exp: `{"input": {"bar": 1}, "erased": ["/input/:path"]}`,
|
||||
},
|
||||
{
|
||||
note: "upsert input: special character in path",
|
||||
ptr: &maskRule{
|
||||
OP: maskOPUpsert,
|
||||
Path: "/input/:path",
|
||||
Value: "upserted",
|
||||
},
|
||||
event: `{"input": {"bar": 1, ":path": "token"}}`,
|
||||
exp: `{"input": {"bar": 1, ":path": "upserted"}, "masked": ["/input/:path"]}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
|
||||
Reference in New Issue
Block a user