Skip to content
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

feat: retire: Include CVEs as Alert Tags when available #3798

Merged
merged 1 commit into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions addOns/retire/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ All notable changes to this add-on will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

### Changed
- Relevant CVEs will now be added as Alert Tags when available.

## [0.11.0] - 2022-05-03
### Changed
- Updated with upstream retire.js pattern changes.



## [0.10.0] - 2022-02-02
### Changed
- Updated with upstream retire.js pattern changes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.zaproxy.addon.retire;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -71,4 +72,11 @@ public void setOtherinfo(String otherinfo) {
public boolean hasOtherInfo() {
return otherinfo != null && !otherinfo.isEmpty();
}

public Set<String> getCves() {
if (information.isEmpty() || !information.containsKey(CVE)) {
return Collections.emptySet();
}
return information.get(CVE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -101,6 +102,7 @@ private AlertBuilder buildAlert(Result result, String otherInfo) {
Constant.messages.getString(
"retire.rule.desc", result.getFilename(), result.getVersion()))
.setOtherInfo(otherInfo)
.setTags(getAllAlertTags(result))
.setReference(getDetails(Result.INFO, result.getInformation()))
.setSolution(Constant.messages.getString("retire.rule.soln", result.getFilename()))
.setEvidence(result.getEvidence().trim())
Expand All @@ -127,6 +129,13 @@ private String getDetails(String key, Map<String, Set<String>> info) {
return sb.toString();
}

private Map<String, String> getAllAlertTags(Result result) {
Map<String, String> alertTags = new HashMap<>();
result.getCves().forEach(value -> alertTags.put(value, ""));
alertTags.putAll(getAlertTags());
return alertTags;
}

@Override
public Map<String, String> getAlertTags() {
return ALERT_TAGS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ void shouldRaiseAlertOnVulnerableContent() {
assertEquals(
"https://github.com/twbs/bootstrap/issues/20184\n",
alertsRaised.get(0).getReference());
// Two Constant OWASP tags plus one CVE
assertEquals(3, alertsRaised.get(0).getTags().size());
}

@Test
Expand Down