Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sasikanthala opened this issue Jan 20, 2025 · 2 comments
Open
Labels

Comments

@sasikanthala
Copy link

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"}}
@danhhuynh25029
Copy link

I will check the bug

@anderseknert
Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants