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

[K9VULN-2465] Add validation of package names #1512

Merged
merged 3 commits into from
Jan 2, 2025
Merged

Conversation

juli1
Copy link
Contributor

@juli1 juli1 commented Dec 24, 2024

What problem are you trying to solve?

Clients are sending us package names for Python with invalid characters. We want to start filtering these names. They are filtered in the API.

Solution

Warn the user about invalid package names for Python. This is not removing for the payload as this is done by the API. It warns the user about a malformed payload.

Testing

Added units tests

Tried locally with a SBOM and a library containing the name cloud picke (with a space).

Screenshot 2024-12-23 at 8 18 53 PM

@juli1 juli1 requested review from a team as code owners December 24, 2024 01:19
@juli1 juli1 requested a review from dastrong December 24, 2024 01:19
@juli1 juli1 added the static-analysis Related to [sarif, sbom] label Dec 24, 2024
@datadog-datadog-prod-us1
Copy link

Datadog Report

Branch report: juli1/K9VULN-2465
Commit report: b5a6958
Test service: datadog-ci-tests

✅ 0 Failed, 420 Passed, 0 Skipped, 1m 51.7s Total duration (1m 58.8s time saved)

Copy link
Contributor

@dastrong dastrong left a comment

Choose a reason for hiding this comment

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

Left one code suggestion that I think we should make, but won't block on it.

Comment on lines +152 to +155
const pythonPackaNameRegex = new RegExp('^[a-zA-Z0-9][a-zA-Z0-9\\-_.]*[a-zA-Z0-9]$')

export const validateDependencyName = (dependency: Dependency): boolean => {
if (dependency.language === DependencyLanguage.PYTHON && !pythonPackaNameRegex.test(dependency.name)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const pythonPackaNameRegex = new RegExp('^[a-zA-Z0-9][a-zA-Z0-9\\-_.]*[a-zA-Z0-9]$')
export const validateDependencyName = (dependency: Dependency): boolean => {
if (dependency.language === DependencyLanguage.PYTHON && !pythonPackaNameRegex.test(dependency.name)) {
const pythonPackageNameRegex = new RegExp('^[a-zA-Z0-9][a-zA-Z0-9\\-_.]*[a-zA-Z0-9]$')
export const validateDependencyName = (dependency: Dependency): boolean => {
if (dependency.language === DependencyLanguage.PYTHON && !pythonPackageNameRegex.test(dependency.name)) {

Comment on lines +81 to +91
export const renderPayloadWarning = (dependencies: Dependency[]): string => {
let ret = ''

for (const dep of dependencies) {
if (!validateDependencyName(dep)) {
ret += `invalid dependency name ${dep.name}\n`
}
}

return ret
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we prettify this information similar to what we do in renderMissingTags, so it's easier to notice for end-users?

Suggested change
export const renderPayloadWarning = (dependencies: Dependency[]): string => {
let ret = ''
for (const dep of dependencies) {
if (!validateDependencyName(dep)) {
ret += `invalid dependency name ${dep.name}\n`
}
}
return ret
}
export const renderPayloadWarning = (dependencies: Dependency[]): string => {
const errors = []
for (const dep of dependencies) {
if (!validateDependencyName(dep)) {
errors.push(chalk.red(` - invalid dependency name ${dep.name}\n`))
}
}
if (errors.length === 0) {
return ''
}
let baseHeading = 'The following issues were detected:\n'
return baseHeading += errors.join('')
}

@juli1 juli1 merged commit da09721 into master Jan 2, 2025
17 checks passed
@juli1 juli1 deleted the juli1/K9VULN-2465 branch January 2, 2025 12:59
@AntoineDona AntoineDona mentioned this pull request Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
static-analysis Related to [sarif, sbom]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants