Skip to content

Commit 758df6d

Browse files
authored
Filter out SHA OCI versions from CVE remediation (#237)
Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>
1 parent 32fd6ff commit 758df6d

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

.github/scripts/cve-scan-helper-remediation.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ find_compatible_upgrade() {
182182
local target_tag=""
183183

184184
for tag in "${tag_array[@]}"; do
185+
# Filter hex strings (7+ chars) containing at least one hex letter.
186+
if [[ "$tag" =~ ^[A-Fa-f0-9]{7,}$ ]] && [[ "$tag" =~ [A-Fa-f] ]]; then
187+
continue
188+
fi
189+
185190
parse_output=$(parse_version "$tag" 2>/dev/null) || continue
186191

187192
local tag_version="${parse_output%|*}"

.github/scripts/tests/cve-scan-helper-remediation.bats

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,45 @@ setup() {
198198
[ "$result" = "2.0.0" ]
199199
}
200200

201+
@test "find_compatible_upgrade: skips Git SHAs of all lengths" {
202+
# Current: 3.1.2
203+
# Available: SHAs (7-char, 40-char SHA-1, 64-char SHA-256), valid versions
204+
# Should return: 3.2.0 (all SHAs filtered, selects highest valid)
205+
local tags=(
206+
"abcdef7" # 7-char short SHA
207+
"7012366806370b50d3a915116d31ed373a1e8e70" # 40-char SHA-1
208+
"abc1234567890abcdef1234567890abcdef1234567890abcdef1234567890ab" # 64-char SHA-256
209+
"3.2.0"
210+
"3.1.3"
211+
)
212+
local result
213+
result=$(find_compatible_upgrade "3.1.2" "${tags[@]}")
214+
215+
[ "$result" = "3.2.0" ]
216+
}
217+
218+
@test "find_compatible_upgrade: returns empty when only SHAs available" {
219+
# Current: 3.1.2
220+
# Available: only SHAs (no valid versions)
221+
# Should return: empty
222+
local tags=("abc1234" "7012366806370b50d3a915116d31ed373a1e8e70")
223+
local result
224+
result=$(find_compatible_upgrade "3.1.2" "${tags[@]}")
225+
226+
[ -z "$result" ]
227+
}
228+
229+
@test "find_compatible_upgrade: allows numeric-only tags" {
230+
# Current: 20240101
231+
# Available: numeric date tags (no letters), SHA (has letters)
232+
# Should return: 20240707 (numeric tags allowed, SHAs filtered)
233+
local tags=("20240707" "abc1234" "20240101" "1234567")
234+
local result
235+
result=$(find_compatible_upgrade "20240101" "${tags[@]}")
236+
237+
[ "$result" = "20240707" ]
238+
}
239+
201240
# ============================================================================
202241
# verify-image step Tests
203242
# ============================================================================

0 commit comments

Comments
 (0)