-
Notifications
You must be signed in to change notification settings - Fork 29
tim code #1662
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
tim code #1662
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||||||||||||||||||
| // Copyright 2026 larshermges | ||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||
| // you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||
| // You may obtain a copy of the License at | ||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||
| // Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||
| // See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||
| // limitations under the License. | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| package normalize | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import "strings" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| func UppercaseCVEID(cveID string) string { | ||||||||||||||||||||||||||||
| // make sure ghsa is uppercase | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| // make sure ghsa is uppercase | |
| // ensure GHSA prefix is uppercase and normalize the rest |
Copilot
AI
Feb 6, 2026
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.
UppercaseCVEID can panic for inputs like "ghsa" (no '-' present): prefix becomes "ghsa" and cveID[len(prefix)+1:] slices past the string length. Consider using strings.Cut/SplitN and only slicing when a '-' separator is present; otherwise fall back to returning strings.ToUpper(cveID) (or another safe default).
| prefix := strings.Split(cveID, "-")[0] | |
| switch strings.ToLower(prefix) { | |
| case "ghsa": | |
| return "GHSA-" + strings.ToLower(cveID[len(prefix)+1:]) | |
| prefix, rest, found := strings.Cut(cveID, "-") | |
| if !found { | |
| // No '-' present: fall back to uppercasing the whole ID to avoid panics. | |
| return strings.ToUpper(cveID) | |
| } | |
| switch strings.ToLower(prefix) { | |
| case "ghsa": | |
| return "GHSA-" + strings.ToLower(rest) |
Copilot
AI
Feb 6, 2026
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.
The function name UppercaseCVEID is misleading because the GHSA branch returns a mixed-case value (prefix uppercased, suffix lowercased). Consider renaming to something like NormalizeVulnID/NormalizeCVEID (or adjust behavior to truly uppercase everything) so callers don’t misinterpret what it guarantees.
| // make sure ghsa is uppercase | |
| // extract the prefix | |
| prefix := strings.Split(cveID, "-")[0] | |
| switch strings.ToLower(prefix) { | |
| case "ghsa": | |
| return "GHSA-" + strings.ToLower(cveID[len(prefix)+1:]) | |
| default: | |
| return strings.ToUpper(cveID) | |
| } | |
| return strings.ToUpper(cveID) |
Copilot
AI
Feb 6, 2026
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.
UppercaseCVEID is new behavior used to normalize request parameters for CSAF report lookup, but there are no unit tests covering GHSA vs CVE inputs or malformed values (e.g., "ghsa" without a dash). Adding a small table-driven test would protect against regressions and the panic case.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -795,7 +795,7 @@ func GenerateCSAFReport(ctx shared.Context, dependencyVulnRepository shared.Depe | |
| org := shared.GetOrg(ctx) | ||
| asset := shared.GetAsset(ctx) | ||
| // remove everything <asset-slug>_ from the beginning of the document id | ||
| cveID = strings.ToUpper(strings.Split(cveID, ".json")[0]) | ||
| cveID = normalize.UppercaseCVEID(strings.Split(cveID, ".json")[0]) | ||
|
Comment on lines
797
to
+798
|
||
|
|
||
| // fetch the cve from the database | ||
| vulns, err := dependencyVulnRepository.GetDependencyVulnByCVEIDAndAssetID(nil, cveID, asset.ID) | ||
|
|
||
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.
The repository is licensed under AGPL-3.0 (see LICENSE.txt), but this new file introduces an Apache-2.0 header. Unless this file is explicitly excluded/relicensed, the header should match the project’s AGPL notice to avoid licensing/compliance conflicts.