-
Notifications
You must be signed in to change notification settings - Fork 678
Fix uncontrolled command line in V4L2 #3160
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: dev
Are you sure you want to change the base?
Conversation
Signed-off-by: MichaIng <[email protected]>
Remove setup.cfg, merging all info into pyproject.toml: - https://packaging.python.org/en/latest/specifications/pyproject-toml/ - https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html We follow latest standards, hence the raised minimum setuptools version to support [project.license]. The URL names are also chosen to have max overlap with those supported/visualised on PyPI: - https://docs.pypi.org/project_metadata/ Signed-off-by: MichaIng <[email protected]>
This reverts commit 87132aa.
Fix the issue need to ensure that user-provided input is sanitized or validated before being passed to `subprocess.run`. The best approach is to implement an allowlist of acceptable commands or arguments and reject any input that does not match the allowlist. Additionally, we should avoid using `shell=True` wherever possible, as it significantly increases the risk of command injection. **Steps to fix:** 1. Introduce an allowlist of valid commands or arguments in `motioneye/controls/v4l2ctl.py` for the `list_resolutions` function. 2. Validate the `device` parameter against this allowlist before constructing the `cmd` string. 3. Modify `call_subprocess` in `motioneye/utils/__init__.py` to reject unsafe inputs or enforce stricter validation. 4. Ensure that all paths leading to `call_subprocess` sanitize or validate user input.
IMO there is no point to sanitize But it generally makes sense to sanitize any kind of user input, including output of external commands. I am not 100% sure, but AFAIK I'll turn this into a draft, since with hardcoded example allow losts, it is not ready to be tested, but a discussion basis. Regarding |
motioneye/motioneye/controls/v4l2ctl.py
Line 98 in 5158ddc
motioneye/motioneye/utils/__init__.py
Line 664 in 5158ddc
Fix the issue need to ensure that user-provided input is sanitized or validated before being passed to
subprocess.run
. The best approach is to implement an allowlist of acceptable commands or arguments and reject any input that does not match the allowlist. Additionally, we should avoid usingshell=True
wherever possible, as it significantly increases the risk of command injection.Steps to fix:
motioneye/controls/v4l2ctl.py
for thelist_resolutions
function.device
parameter against this allowlist before constructing thecmd
string.call_subprocess
inmotioneye/utils/__init__.py
to reject unsafe inputs or enforce stricter validation.call_subprocess
sanitize or validate user input.Code that passes user input directly to
exec
,eval
, or some other library routine that executes a command, allows the user to execute malicious code. The following shows two functions. The first is unsafe as it takes a shell script that can be changed by a user, and passes it straight tosubprocess.call()
without examining it first. The second is safe as it selects the command from a predefined allowlist.