Skip to content

Commit a1ecee7

Browse files
committed
Add kind/cve label after receiving the CVE ID
Signed-off-by: Bruno Oliveira da Silva <bruno@abstractj.com>
1 parent 8d08159 commit a1ecee7

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

src/main/java/org/keycloak/gh/bot/labels/Kind.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
public enum Kind {
44

5-
BUG;
5+
BUG,
6+
CVE;
67

78
@Override
89
public String toString() {

src/main/java/org/keycloak/gh/bot/security/email/MailProcessor.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.eclipse.microprofile.config.inject.ConfigProperty;
1010
import org.jboss.logging.Logger;
1111
import org.keycloak.gh.bot.GitHubInstallationProvider;
12+
import org.keycloak.gh.bot.labels.Kind;
1213
import org.keycloak.gh.bot.labels.Status;
1314
import org.keycloak.gh.bot.security.common.Constants;
1415
import org.keycloak.gh.bot.utils.Labels;
@@ -249,13 +250,19 @@ void applyCveIdFromSecAlert(GHIssue issue, String subject, String body) throws I
249250
issue.setTitle(newTitle);
250251
LOGGER.infof("Replaced %s with [%s] in issue #%d", Constants.CVE_TBD_PREFIX, cveId, issue.getNumber());
251252

252-
boolean hasCveRequestLabel = issue.getLabels().stream()
253+
var labelNames = issue.getLabels().stream()
253254
.map(GHLabel::getName)
254-
.anyMatch(Status.CVE_REQUEST.toLabel()::equals);
255-
if (hasCveRequestLabel) {
255+
.toList();
256+
257+
if (labelNames.contains(Status.CVE_REQUEST.toLabel())) {
256258
issue.removeLabels(Status.CVE_REQUEST.toLabel());
257259
LOGGER.infof("Removed %s label from issue #%d", Status.CVE_REQUEST.toLabel(), issue.getNumber());
258260
}
261+
262+
if (!labelNames.contains(Kind.CVE.toLabel())) {
263+
issue.addLabels(Kind.CVE.toLabel());
264+
LOGGER.infof("Added %s label to issue #%d", Kind.CVE.toLabel(), issue.getNumber());
265+
}
259266
}
260267
}
261268

src/test/java/org/keycloak/gh/bot/security/email/MailProcessorTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.junit.jupiter.api.Test;
44
import org.junit.jupiter.params.ParameterizedTest;
55
import org.junit.jupiter.params.provider.CsvSource;
6+
import org.keycloak.gh.bot.labels.Kind;
67
import org.keycloak.gh.bot.labels.Status;
78
import org.kohsuke.github.GHIssue;
89
import org.kohsuke.github.GHLabel;
@@ -102,6 +103,7 @@ void applyCveIdFromSecAlert_replacesTitleAndRemovesCveRequestLabel() throws Exce
102103

103104
verify(issue).setTitle("[CVE-2026-9999] XSS in admin console");
104105
verify(issue).removeLabels(Status.CVE_REQUEST.toLabel());
106+
verify(issue).addLabels(Kind.CVE.toLabel());
105107
}
106108

107109
@Test
@@ -116,6 +118,7 @@ void applyCveIdFromSecAlert_doesNotRemoveLabelWhenNotPresent() throws Exception
116118

117119
verify(issue).setTitle("[CVE-2026-9999] XSS in admin console");
118120
verify(issue, never()).removeLabels(Status.CVE_REQUEST.toLabel());
121+
verify(issue).addLabels(Kind.CVE.toLabel());
119122
}
120123

121124
@Test
@@ -128,6 +131,7 @@ void applyCveIdFromSecAlert_noOpWhenTitleDoesNotStartWithCveTbd() throws Excepti
128131

129132
verify(issue, never()).setTitle(org.mockito.ArgumentMatchers.anyString());
130133
verify(issue, never()).removeLabels(org.mockito.ArgumentMatchers.any(String[].class));
134+
verify(issue, never()).addLabels(org.mockito.ArgumentMatchers.any(String[].class));
131135
}
132136

133137
@Test
@@ -145,5 +149,23 @@ void applyCveIdFromSecAlert_extractsCveFromBodyWhenNotInSubject() throws Excepti
145149

146150
verify(issue).setTitle("[CVE-2026-5555] SSRF vulnerability");
147151
verify(issue).removeLabels(Status.CVE_REQUEST.toLabel());
152+
verify(issue).addLabels(Kind.CVE.toLabel());
153+
}
154+
155+
@Test
156+
void applyCveIdFromSecAlert_doesNotAddCveKindWhenAlreadyPresent() throws Exception {
157+
GHIssue issue = mock(GHIssue.class);
158+
when(issue.getTitle()).thenReturn("[CVE-TBD] OIDC token leak");
159+
when(issue.getNumber()).thenReturn(77);
160+
161+
GHLabel cveKindLabel = mock(GHLabel.class);
162+
when(cveKindLabel.getName()).thenReturn(Kind.CVE.toLabel());
163+
when(issue.getLabels()).thenReturn(List.of(cveKindLabel));
164+
165+
MailProcessor processor = new MailProcessor();
166+
processor.applyCveIdFromSecAlert(issue, "CVE-2026-8888 OIDC token leak", "body");
167+
168+
verify(issue).setTitle("[CVE-2026-8888] OIDC token leak");
169+
verify(issue, never()).addLabels(Kind.CVE.toLabel());
148170
}
149171
}

0 commit comments

Comments
 (0)