opa icon indicating copy to clipboard operation
opa copied to clipboard

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

Open sasikanthala opened this issue 11 months ago • 3 comments

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"}}

sasikanthala avatar Jan 20 '25 03:01 sasikanthala

I will check the bug

danhhuynh25029 avatar Jan 20 '25 08:01 danhhuynh25029

Interesting. I don't recall us having made any changes in that code recently. I wonder if it could be some dependency that changed? Oh well, I guess we'll find out eventually. Thanks for reporting it!

anderseknert avatar Jan 20 '25 18:01 anderseknert

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue.

stale[bot] avatar Feb 21 '25 08:02 stale[bot]