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

Sanitize dynamic version value #183

Open
sanmai-NL opened this issue Jun 10, 2023 · 2 comments
Open

Sanitize dynamic version value #183

sanmai-NL opened this issue Jun 10, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@sanmai-NL
Copy link
Contributor

sanmai-NL commented Jun 10, 2023

Is your feature request related to a problem? Please describe.

https://pdm-backend.fming.dev/metadata/#writing-dynamic-version-to-file suggests a procedure for writing a package version to a file. Python source code generation is also described. Generating source code with unsanitized input is dangerous (CWE-20).

Describe the solution you'd like

As a security conscious developer, I want PDM to sanitize the version string that is replaced in the template, so that when something unexpected happens (e.g., env var is tainted in a CI pipeline), a code injection vulnerability is mitigated.

Besides the existing {} (‘raw string’) placeholder which puts the raw version characters in the file, add, e.g., a placeholder{str_version} that directly inserts a quoted (non-f-)string.

Warn when the raw string placeholder is used, both in the docs and at runtime.

Alternatively, deprecate the feature to write the version file according a template.

@sanmai-NL sanmai-NL added the enhancement New feature or request label Jun 10, 2023
@sanmai-NL sanmai-NL changed the title Sanitize dynamic version value [PDM 2.7.1] Sanitize dynamic version value Jun 10, 2023
@frostming frostming transferred this issue from pdm-project/pdm Jun 12, 2023
@frostming frostming changed the title [PDM 2.7.1] Sanitize dynamic version value Sanitize dynamic version value Jun 12, 2023
@frostming
Copy link
Contributor

Your concern mostly makes sense. But IMO the situation is not worse than the setup.py style metadata. Anyway, PR welcomed.

@sanmai-NL
Copy link
Contributor Author

That's true, but it would be nice if PDM would differentiate itself even at software security. 🙂 And not having offered the template feature or not providing an example of writing source code (security-by-default) would have be a low-cost way to avoid the risk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants