Skip to content

pytest-pouch: replace shell=True subprocess calls with argv lists#170

Draft
mniestroj wants to merge 1 commit into
mainfrom
pytest-pouch-use-subprocess-run-without-shell
Draft

pytest-pouch: replace shell=True subprocess calls with argv lists#170
mniestroj wants to merge 1 commit into
mainfrom
pytest-pouch-use-subprocess-run-without-shell

Conversation

@mniestroj

Copy link
Copy Markdown
Collaborator

This eliminates potential command-injection risk from interpolated
device.name and project.id values. File paths are built with Path joins and
passed as explicit arguments instead of being embedded in shell command
strings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens pytest-pouch’s credential-generation fixture by removing shell=True subprocess usage and passing explicit argv lists/paths to OpenSSL, reducing command-injection risk from interpolated device.name / project.id values.

Changes:

  • Replaced OpenSSL shell command strings with argv lists passed to subprocess.run(...).
  • Built certificate/key file paths using Path joins and passed them as explicit OpenSSL arguments.
  • Updated certificate upload to read from the new Path variable (ca_crt).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +109 to +114
"-CA",
str(ca_crt),
"-CAkey",
str(ca_key),
"-CAcreateserial",
"-out",

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openssl x509 -CAcreateserial will create the serial file (default ca.srl) in the process working directory unless -CAserial is provided. Since cwd=creds_dir was removed, this can leak ca.srl into whatever directory pytest is run from and can also break parallel runs. Pass an explicit -CAserial path under creds_dir (or restore cwd=creds_dir) so all generated artifacts stay contained.

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +36
dev_key = creds_dir / f"{device.name}.key.pem"
dev_csr = creds_dir / f"{device.name}.csr.pem"
dev_crt = creds_dir / f"{device.name}.crt.pem"

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

device.name is used directly in credential filenames. If it contains path separators (e.g. /, \\) or .., Path joining can write outside creds_dir or create unexpected subdirectories, which is a security and correctness problem even without shell=True. Consider validating/normalizing device.name into a safe filename component (e.g., allowlist characters and reject/replace separators) before building these paths.

Copilot uses AI. Check for mistakes.
Base automatically changed from http-client-pytest to pytest-style April 17, 2026 15:31
Base automatically changed from pytest-style to main April 17, 2026 15:45
This eliminates potential command-injection risk from interpolated
device.name and project.id values. File paths are built with Path joins and
passed as explicit arguments instead of being embedded in shell command
strings.

Signed-off-by: Marcin Niestroj <marcin.niestroj@canonical.com>
@mniestroj mniestroj force-pushed the pytest-pouch-use-subprocess-run-without-shell branch from 0e2f262 to 2566a4f Compare April 17, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants