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

JSON schema validation of a string against a regex pattern does not work #6089

Open
ewout8 opened this issue Jul 12, 2023 · 6 comments
Open

Comments

@ewout8
Copy link

ewout8 commented Jul 12, 2023

Short description

JSON validation of a string against a regex pattern does not work. All strings are valid, regardless of the pattern in the json-schema.

Steps To Reproduce

https://play.openpolicyagent.org/p/bp1bkcvv0y

Expected behavior

Strings that do not match the regex pattern cause the JSON validation to fail.

@ewout8 ewout8 added the bug label Jul 12, 2023
@charlieegan3 charlieegan3 changed the title JSON validation of a string against a regex pattern does not work JSON schema validation of a string against a regex pattern does not work Jul 12, 2023
@charlieegan3
Copy link
Contributor

Thanks for opening this issue @ewout8.

Here's another playground example showing that the schema is also valid: https://play.openpolicyagent.org/p/fmjL7tdsde

Anyone else running into this issue in the meantime, might be able to use regex.match to validate using regular expressions.

@anderseknert
Copy link
Member

This was intentionally disabled for the purpose of type checking, where the pattern serves no meaningful purpose, but still would have some schemas fail the entire policy compilation process as the RE2 dialect used by Golang/OPA would choke on anything from the Javascript Regex dialect from JSON schema it did not understand, like negative lookahead.

This was before these new JSON schema related built-in functions were added though. For those, pattern property validation makes sense, although with the same caveat as mentioned above, that some patterns are simply going to fail even if "valid".

I haven't looked into it, but I can imagine it'll be hairy to try and make this conditional, as we had to patch the vendored code in order to fix this.

@ewout8
Copy link
Author

ewout8 commented Jul 12, 2023

If it was intentionally disabled I would expect the validation of the schema itself to fail, or at least some warning. The whole purpose of validating the input for me is not having to do checks in policy rules. My best option now is validating the input document outside OPA I guess.

@anderseknert
Copy link
Member

Perhaps I wasn't clear enough — pattern validation was not intentionally disabled for these built-in functions. It couldn't have been, as they did not exist at the time 🙂 The JSON schema library we depend on is used for another purpose in OPA, which is (optional) enhanced compile time type checking. Pattern validation makes no sense in that context, but still managed to fail some cases where an unknown pattern was provided and because of that it was disabled.

The problem is that these built-in functions depend on the same patched JSON schema library where we had to disable that, so the challenge will be to make that feature conditional.. i.e. keep it disabled for type checking while have it enabled for the schema validation built-in functions.

@stale
Copy link

stale bot commented Aug 12, 2023

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.

@mscudlik
Copy link

mscudlik commented Jul 4, 2024

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

4 participants