-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Security considerations #1361
Comments
Excellent question. So far we've held back from adding the sorts of builtins that might make it easier to break out of the jq sandbox. Real or potential issues to be concerned with:
Now, it is my intention to require the use of a command-line switch to enable future I/O builtins that could allow reading or writing files, or executing external programs. But still, there's no way to guarantee that's so. I think it's probably desirable to add a command-line option to disallow the main program from including files or modules, or more generally a sandbox option. |
Ah, excellent. Thanks! Out of those, the include and import statements seem concerning under most threat models (including ours.) +1 for sandboxed mode flag for this and future features :) Items like DOS via resource abuse are real concerns, and I agree with others that we'd normally go to to the OS etc. for handling that. For the interim, would it be sufficient for us to do a blacklist for "include" and "import", and freeze to the current version? |
@lmeyerov Yes. You might even edit Thinking about how to disable |
There's a lot of potential sandboxing options:
Eventually we'll have fairly capable I/O builtins. We might have a need for many sandboxing options. Obviously, @lmeyerov, the simplest sandbox will be to |
Actually, that may well be the best thing we could do: have a "chroot" option that disallows I/O to/from files outside the sandbox. On Unix-like systems jq would then literally call |
It may help, as simple policies, to consider two of the most basic security properties: data confidentiality & integrity. I'd expect "--sandbox" to provide both. Integrity doesn't seem to be an issue, but confidentiality would seem to require disallowing both module & data import, as who knows what's on the system. (I'm assuming the attacker can control the data & transform parameters, but not the rest, and there is a chance of dangerous files already on the system for use as part of an escalation.) Making "--sandbox" target a model like that, and supporting it going forwards, would provide a simple policy for both use & development. FWIW, we're using JQ via https://github.com/sanack/node-jq, so patching it with |
This thread is now almost 4 years old, but seems like it should be raised again. We are very much interested in a "--sandbox" option. Our use case is that a client can supply a JQ filter allow with an RestAPI call so that the server only returns a subset of the data. Note: GraphQL and similar are not a good fit for us at this time. I am loath to re-implement the syntax, create a library to sanitize the input (which would be just as difficult as reimplementing jq), or use a custom built version which does not contain the insecure builtins and variables. Is there anything we can do to contribute to a "--sandbox" option or an alternative build with those insecurities taken out, suitable for embedding? |
If a PR was submitted to add a Any notes from the maintainers about acceptance criteria for somebody who wants to do that PR? |
Some use cases for `jq` may involve accepting untrusted input. See discussion in jqlang#1361 for some security considerations that may be relevant for those use cases. This commit adds a `--sandbox` flag which is meant to mitigate one category of security issue with untrusted input: features of jq which are meant to let the jq filter access files/data other than the direct input data given to the CLI. Specifically, the new `--sandbox` flag blocks the implicit loading of `$HOME/.jq`, and also blocks the use of `import` and `include` for loading other `jq` files. If other features are added to `jq` in the future which allow for reading files/data as part of the filter syntax, it is intended that the `--sandbox` flag would also gate access to those.
Okay, this was a simple enough change that I decided to go ahead and create a pull request to add the Hopefully that can mitigate at least this category of risk (including/importing arbitrary files/data from the file system), if the PR is accepted. |
We're considering allowing user-defined transforms specified in jq, but it has been difficult for us to ascertain how safe it is from code injection & privilege escalation, by design & in practice. As far as I can tell, while jq supports some user-defined functions, they are largely sandboxed. The exception is the module imports, which would need some thing for restricting.
Can anyone clarify the security model? May help to link the answer as part of the README.
The text was updated successfully, but these errors were encountered: