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

fix(pip): Validate package names and versions #6750

Closed
knqyf263 opened this issue May 22, 2024 · 0 comments · Fixed by #6804
Closed

fix(pip): Validate package names and versions #6750

knqyf263 opened this issue May 22, 2024 · 0 comments · Fixed by #6804
Assignees
Labels
scan/sbom Issues relating to SBOM
Milestone

Comments

@knqyf263
Copy link
Collaborator

Description

A repository may have requirements.txt with a templating engine which is being used to generate the final requirements.txt file.
For example, this is a line from the mentioned requirements.txt file:

%ifcookiecutter.command_line_interface|lower=='click'-%}

Since we scan all requirements.txt files while doing a file system scan, we would be splitting the line by == to get the package name and version (as per logic here). It's better to add some validation against package names and versions, such as if the name doesn't use invalid characters, the version follows PEP440, etc.

{
      "Target": "opt/conda/pkgs/cookiecutter-2.6.0-py311h06a4308_0/info/test/tests/test-templates/include/{{cookiecutter.project_slug}}/requirements.txt",
      "Class": "lang-pkgs",
      "Type": "pip",
      "Packages": [
        {
          "Name": "{%ifcookiecutter.command_line_interface|lower",
          "Identifier": {
            "PURL": "pkg:pypi/%7B%25ifcookiecutter.command-line-interface%7Clower@%27click%27-%25%7D"
          },
          "Version": "'click'-%}",
          "Layer": {}
        },
        {
          "Name": "{%ifcookiecutter.use_pytest",
          "Identifier": {
            "PURL": "pkg:pypi/%7B%25ifcookiecutter.use-pytest@%27y%27-%25%7D"
          },
          "Version": "'y'-%}",
          "Layer": {}
        }
      ]
    }

Reference

aquasecurity/go-dep-parser#307

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scan/sbom Issues relating to SBOM
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants