cve: Fix escaping of CPE
cover cve: Fix escaping of CPE
This series tries to fix the regression introduced by commit 9dd9c0038907 ("cve_check: Escape special characters in CPE 2.3 strings")
CVE_PRODUCT was already escaped. Now it no longer needs to be escaped, otherwise double escaping is realized.
Also add a patch in this series that try to handle the transition between the previous behavior and the new one.
---
Benjamin Robin (4):
cve_check: Improve escaping of special characters in CPE 2.3
cve_check: do not break old CVE_PRODUCT with escaped + gtk+: Remove escaping of the plus sign in CVE_PRODUCT
webkitgtk: Remove escaping of the plus sign in CVE_PRODUCT
meta/lib/oe/cve_check.py | 29 ++++++++++++++-------------- meta/recipes-gnome/gtk+/gtk+3_3.24.51.bb | 2 +- meta/recipes-sato/webkit/webkitgtk_2.50.6.bb | 2 +- 3 files changed, 16 insertions(+), 17 deletions(-)
---
base-commit: 853baa702e3275fc8b4dc492a93d9a00c8cf5c0f
change-id: 20260410-fix-cpe-escaping-5bc9a67a8d13
Best regards,
Signature · 1 line
Benjamin Robin <[email protected]>
PATCH 1/4 cve_check: Improve escaping of special characters in CPE 2.3
According to the NISTIR 7695 specification [1], multiple characters require escaping when using formatted strings (e.g., cpe:2.3:...), which use backslash escaping. In "Figure 6-3. ABNF for Formatted String Binding"", the characters that need escaping are referenced by "escape", "special", and "punc". More characters must be escaped than just \, ?, *, :, and +.
Additionally, use maketrans() with translate(), which is more efficient than a simple replace().
[1] https://nvlpubs.nist.gov/nistpubs/legacy/ir/nistir7695.pdf
--- meta/lib/oe/cve_check.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-)
meta/lib/oe/cve_check.py +12 -16
@@ -205,33 +205,29 @@ def get_patched_cves(d): return patched_cves +_CPE23_ENCODE_TRANS_TABLE = str.maketrans( + {c: f"\\{c}" for c in [ + "\\", "!", '"', "#", "$", "%", "&", "'", "(", ")", "+", ",", "/", ":", ";", + "<", "=", ">", "@", "[", "]", "^", "`", "{", "|", "}", "~", "?", "*" + ]} +) + + def cpe_escape(value): - r""" + """ Escape special characters for CPE 2.3 formatted string binding. CPE 2.3 formatted string binding (cpe:2.3:...) uses backslash escaping for special meta-characters, NOT percent-encoding. Percent-encoding is only used in the URI binding (cpe:/...). - According to NISTIR 7695, these characters need escaping: - - Backslash (\) -> \\ - - Question mark (?) -> \? - - Asterisk (*) -> \* - - Colon (:) -> \: - - Plus (+) -> \+ (required by some SBOM validators) + According to NISTIR 7695, various characters referenced in the "Figure 6-3. + ABNF for Formatted String Binding" need escaping: escape, special and punc. """ if not value: return value - # Escape special meta-characters for CPE 2.3 formatted string binding - # Order matters: escape backslash first to avoid double-escaping - result = value.replace('\\', '\\\\') - result = result.replace('?', '\\?') - result = result.replace('*', '\\*') - result = result.replace(':', '\\:') - result = result.replace('+', '\\+') - - return result + return value.translate(_CPE23_ENCODE_TRANS_TABLE) def get_cpe_ids(cve_product, version):
Signature · 1 line
2.53.0
PATCH 2/4 cve_check: do not break old CVE_PRODUCT with escaped +
In reply to Benjamin RobinFor now, until all layer are fixed, replace already escaped plus (+) with a simple + before doing the escaping.
--- meta/lib/oe/cve_check.py | 3 +++ 1 file changed, 3 insertions(+)
meta/lib/oe/cve_check.py +3 -0
@@ -227,6 +227,9 @@ def cpe_escape(value): if not value: return value + # Do not break compatibility + value = value.replace("\\+", "+") + return value.translate(_CPE23_ENCODE_TRANS_TABLE)
Signature · 1 line
2.53.0
PATCH 3/4 gtk+: Remove escaping of the plus sign in `CVE_PRODUCT`
In reply to Benjamin RobinThe + character is now properly escaped by cve_check.cpe_escape()
--- meta/recipes-gnome/gtk+/gtk+3_3.24.51.bb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/recipes-gnome/gtk+/gtk+3_3.24.51.bb +1 -1
@@ -9,7 +9,7 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=5f30f0716dfdd0d91eb439ebec522ec2 \ file://gdk/gdk.h;endline=25;md5=c920ce39dc88c6f06d3e7c50e08086f2 \ file://tests/testgtk.c;endline=25;md5=cb732daee1d82af7a2bf953cf3cf26f1" -CVE_PRODUCT = "gnome:gtk gtk:gtk\+" +CVE_PRODUCT = "gnome:gtk gtk:gtk+" DEPENDS = "glib-2.0 cairo pango atk jpeg libpng gdk-pixbuf gdk-pixbuf-native"
Signature · 1 line
2.53.0
PATCH 4/4 webkitgtk: Remove escaping of the plus sign in `CVE_PRODUCT`
In reply to Benjamin RobinThe + character is now properly escaped by cve_check.cpe_escape()
--- meta/recipes-sato/webkit/webkitgtk_2.50.6.bb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/recipes-sato/webkit/webkitgtk_2.50.6.bb +1 -1
@@ -25,7 +25,7 @@ inherit cmake pkgconfig gobject-introspection perlnative features_check upstream ANY_OF_DISTRO_FEATURES = "${GTK3DISTROFEATURES}" REQUIRED_DISTRO_FEATURES = "opengl" -CVE_PRODUCT = "webkitgtk webkitgtk\+" +CVE_PRODUCT = "webkitgtk webkitgtk+" DEPENDS += " \ ruby-native \
Signature · 1 line
2.53.0