-
Notifications
You must be signed in to change notification settings - Fork 55
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
Conversation
Datadog ReportBranch report: ✅ 0 Failed, 420 Passed, 0 Skipped, 1m 51.7s Total duration (1m 58.8s time saved) |
There was a problem hiding this 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.
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)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)) { |
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 | ||
} |
There was a problem hiding this comment.
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?
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('') | |
} |
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).