Repository: opencve/opencve (language: python)

Issue:
CWE link error
Hello,

while navigating and testing, i see a small error in cwe link to mitre: in https://www.opencve.io/cwe

Actual:
http://cwe.mitre.org/data/definitions/**CWE-**998.html
Correct:
http://cwe.mitre.org/data/definitions/998.html

Well, i know, that's a not a big issue...

Best regards


Discussion / hints:
Hi @Ch-Philou ,

Indeed this is something to fix ! The change will be included in the next release, thank you :)

Fix patch:
diff --git a/opencve/models/cwe.py b/opencve/models/cwe.py
index cab78fd5..f513688d 100644
--- a/opencve/models/cwe.py
+++ b/opencve/models/cwe.py
@@ -9,5 +9,11 @@ class Cwe(BaseModel):
     name = db.Column(db.String())
     description = db.Column(db.String())
 
+    @property
+    def short_id(self):
+        if not self.cwe_id.startswith("CWE-"):
+            return None
+        return self.cwe_id.split("CWE-")[1]
+
     def __repr__(self):
         return "<Cwe {}>".format(self.cwe_id)
diff --git a/opencve/templates/cwes.html b/opencve/templates/cwes.html
index f3cd8e18..45cafbf1 100644
--- a/opencve/templates/cwes.html
+++ b/opencve/templates/cwes.html
@@ -34,9 +34,11 @@ <h3 class="box-title">Categories (CWE)</h3>
                                     class="ion-help-circled"></i></a></td>
                             <td class="col-md-3 text-center">
                                 <div class="btn-group">
-                                    <a href="http://cwe.mitre.org/data/definitions/{{ cwe.cwe_id }}.html"
+                                    {% if cwe.cwe_id not in ["NVD-CWE-noinfo", "NVD-CWE-Other"] %}
+                                    <a href="http://cwe.mitre.org/data/definitions/{{ cwe.short_id }}.html"
                                        target="_blank" class="btn btn-xs btn-default"><i
                                             class="fa fa-external-link"></i> Mitre</a>
+                                    {% endif %}
                                     <a href="{{ url_for('main.cves', cwe=cwe.cwe_id) }}"
                                        class="btn btn-xs btn-default"><i class="fa fa-shield"></i> View CVE</a>
                                 </div>


Test patch:
diff --git a/tests/test_models.py b/tests/test_models.py
index ab7e5e06..84fe17c3 100644
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -42,9 +42,16 @@ def test_new_cwe():
     )
     assert str(cwe) == "<Cwe CWE-79>"
     assert cwe.cwe_id == "CWE-79"
+    assert cwe.short_id == "79"
     assert cwe.name == "Improper Neutralization..."
     assert cwe.description == "The software does not..."
 
+    # Try an unusual CWE ID
+    cwe.cwe_id = "NVD-CWE-noinfo"
+    assert str(cwe) == "<Cwe NVD-CWE-noinfo>"
+    assert cwe.cwe_id == "NVD-CWE-noinfo"
+    assert not cwe.short_id
+
 
 def test_new_meta():
     meta = Meta(