-
Notifications
You must be signed in to change notification settings - Fork 274
security: escape Graphviz exec args & validate DBSearch::unserialize … #765
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
base: develop
Are you sure you want to change the base?
Conversation
|
Hello, I have a few questions about your PR : |
Hi @jf-cbd, thank you for the review! Let me address your questions: Context where these issues could occur in iTop:1. Graphviz command injection (graphviz.php) You're correct that $sDotExecutable = MetaModel::GetConfig()->Get('graphviz_path');This config value could potentially contain unexpected characters if:
While the risk is lower since it requires config-level access, using If you prefer, I can:
2. DBSearch::unserialize validation (dbsearch.class.php) This is called from multiple user-facing endpoints that accept serialized filter parameters:
Example attack scenario:
Current code path: $sFilter = utils::ReadParam('filter', '', false, 'raw_data');
$oFilter = DBSearch::unserialize($sFilter); // User-controlled inputThe validation ensures the decoded payload has the expected structure before processing. Re: Default PR templateCould you point me to the template location? I'll update the PR description to follow it. Proposed action:Would you prefer I:
Let me know and I'll update accordingly. Thanks for the careful review! |
|
@nikunj-kohli The template was already linked to by @jf-cbd: https://github.com/Combodo/iTop/blob/develop/.github/pull_request_template.md Please don't use AI to generate PRs, replies and code changes, it puts more burden on maintainers and doesn't help. It is the opposite of helping out and against rules of #Hacktoberfest. Especially these last lines give it away, since that was what the AI agent told You to do, it was not ment to paste this in the PR description:
|
Okay, I'll keep that in my mind. Do you want me to change the format right now or the current one is bearable? |
|
Since this part is the first section of the template, I would say "no, not bearable". <!--
IMPORTANT: Please follow the guidelines within this PR template before submitting it, it will greatly help us process your PR. 🙏
Any PRs not following the guidelines or with missing information will not be considered.
-->Unless you want your PR not to be considered.. |
Alright, I've made the change in PR Description. You can check and let me know if I'm still making a mistake, thankyou for your review. |
|
Thank you for the changes. |
Base information
Symptom (bug) / Objective (enhancement)
DBSearch::unserialize()accepted decoded payloads (urlencoded JSON containing OQL and params) without structural validation or size limits. Since the decoded data flows through multiple request code paths, malformed or excessively large payloads could be processed unexpectedly, with unclear failure modes.dot) invocation using safely quoted arguments and removing unsafe shell input redirection, and (2) validating the structure and size of payloads passed toDBSearch::unserialize()and rejecting invalid or oversized inputs early and cleanly.Reproduction procedure (bug)
(If you need me to provide exact curl commands or a small test script for CI, I can add them — I kept examples high-level here so they are safe for public PR discussion.)
Environment assumptions (please replace with the exact values you want to put in the form if different):
Graphviz unsafe-path scenario:
graphviz_pathin your configuration to an unexpected or malicious value that includes shell metacharacters (for instance: a path containing spaces or characters that the shell would interpret).graphviz_pathto a value containing shell metacharacters.pages/graphviz.php?class=SomeExistingClassgraphviz_pathcould cause the shell to execute unintended tokens.dotcommand is built with escaped arguments and input is passed safely; injection viagraphviz_pathis prevented.DBSearch unserialize malformed/oversized payload:
filterparameter encoded as urlencoded JSON and passed toDBSearch::unserialize()(for example, certain ajax operations in ajax.render.php).filterparameter: e.g.,filter=%7B%22oql%22%3A%22SELECT%20Person%20WHERE%20name%20LIKE%20%27%25A%25%27%22%2C%22params%22%3A%5B%5D%7Dfilterthat is not urlencoded JSON (e.g.,filter=notjson) or a very large payload (e.g., an encoded OQL where theoqlfield contains > 20,000 characters).CoreExceptionand an "Invalid filter parameter" style error, avoiding further processing of malformed/oversized payloads.Cause (bug)
< "$file") and concatenated path components without proper quoting. This allows shell interpretation of certain injected characters in a configuration or input value.DBSearch::unserialize()parsed a urlencoded JSON payload (expected to containoqlandparams) but did not validate the decoded structure or impose limits on the size of the contained OQL string. Because this codepath is used in multiple places (including request-driven ajax endpoints), malformed or extremely large payloads could be passed into DBSearch without clear validation.Proposed solution (bug and enhancement)
What I implemented in this PR:
graphviz.php
dotexecution command using safely quoted arguments (PHP-side escaping) rather than relying on shell input redirection.< "$file"style redirection that previously fed the dot input via the shell.stderrtostdoutsafely while keeping the whole command argument-quoted.graphviz_path(the configured path todot) or other path components were modified or malformed, properly quoting the arguments prevents the shell from interpreting injected tokens.dbsearch.class.php
DBSearch::unserialize():oqlkey (string) and aparamskey (array).oqlstring (e.g., 20_000 characters — reasonable defensive limit; can be tuned).CoreExceptionwith a clear message (e.g., "Invalid filter parameter") when the payload is malformed or exceeds limits.Behavioral notes:
graphviz_pathand inputs are valid.Files changed
dotcommand with escaped arguments; remove shell< fileredirection. (See patch)oql; ensureparamsis an array; throwCoreExceptionon invalid payloads. (See patch)Checklist before requesting a review
DBSearch::unserialize()easily (happy to add a small PHPUnit test), and an integration smoke test can exercise graphviz.php if adotbinary is available in CI.Checklist of things to do before PR is ready to merge
DBSearch::unserialize()for:oqlhitting the limit.graphvizcommand invocation in CI or locally).oqllength limit (current limit is a conservative default and can be tuned).