Skip to content

OPA 1.0.0 get document REST API is broken when path contains backslash. #7282

Open
@sasikanthala

Description

@sasikanthala

Short description

OPA 1.0.0 get document API is broken when path contains backslash character.

curl -XGET 'http://localhost:8181/v1/data/some/path/pa%5Cpa/test2' # backslash character URL encoded to %5C
{
  "code": "internal_error",
  "message": "2 errors occurred:\n1:19: rego_parse_error: illegal escape sequence\n\tdata[\"some\"].path[\"pa\\pa\"].test2\n\t                  ^\n1:19: rego_parse_error: illegal token\n\tdata[\"some\"].path[\"pa\\pa\"].test2\n\t                  ^"
}

Steps To Reproduce

# Running OPA 1.0.0
./opa_darwin_arm64_static_1.0.0 run -s 2>> opa.log &
# Put a document where the path contains backslash character (backslash character URL encoded to %5C)
curl -XPUT 'http://localhost:8181/v1/data/some/path/pa%5Cpa/test2' -d'{"key": "value"}'
# Getting the inserted document
curl -XGET 'http://localhost:8181/v1/data/some/path/pa%5Cpa/test2'
{
  "code": "internal_error",
  "message": "2 errors occurred:\n1:19: rego_parse_error: illegal escape sequence\n\tdata[\"some\"].path[\"pa\\pa\"].test2\n\t                  ^\n1:19: rego_parse_error: illegal token\n\tdata[\"some\"].path[\"pa\\pa\"].test2\n\t                  ^"
}

Expected behavior

This behaves as expected in OPA 0.70.0

# Running OPA 0.70.0
./opa_darwin_arm64_static_0.70.0 run -s 2>> opa.log &
# Put a document where the path contains backslash character (backslash character URL encoded to %5C)
curl -XPUT 'http://localhost:8181/v1/data/some/path/pa%5Cpa/test2' -d'{"key": "value"}'
# Getting the inserted document
curl -XGET 'http://localhost:8181/v1/data/some/path/pa%5Cpa/test2'
{"result":{"key":"value"}}

Additional context

Looks like in 1.0.0 GET API is expecting the path to be quoted in JSON, whereas the PUT is working as before.

# Running OPA 1.0.0
./opa_darwin_arm64_static_1.0.0 run -s 2>> opa.log &
# Put a document where the path contains backslash character (backslash character URL encoded to %5C)
curl -XPUT 'http://localhost:8181/v1/data/some/path/pa%5Cpa/test2' -d'{"key": "value"}'
# Getting the inserted document (NOTE the double backslashes URL encoded as %5C%5C)
curl -XGET 'http://localhost:8181/v1/data/some/path/pa%5C%5Cpa/test2'
{"result":{"key":"value"}}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions