Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class GitHubWebhookService(
throw WebhookSecretNotSetException()
}
if (gitHubEnterpriseProperties.webhookSecret.isNotBlank() && signature256 != null) {
if (!signature256.startsWith("sha256=")) {
logger.error("Invalid signature format, expected 'sha256=' prefix")
throw InvalidEventSignatureException()
}
val hashedSecret = hmacSHA256(gitHubEnterpriseProperties.webhookSecret, payload)
val isEqual = timingSafeEqual(signature256.removePrefix("sha256="), hashedSecret)
if (!isEqual) throw InvalidEventSignatureException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,14 @@ class GitHubWebhookServiceTest {

verify(exactly = 0) { webhookEventService.consumeWebhookEvent(any(), any()) }
}

@Test
fun `should throw InvalidEventSignatureException when signature does not start with sha256=`() {
every { gitHubEnterpriseProperties.baseUrl } returns "known.host"
every { gitHubEnterpriseProperties.webhookSecret } returns "secret"

assertThrows<InvalidEventSignatureException> {
gitHubWebhookService.handleWebhookEvent("PUSH", "known.host", "invalid_signature", "{}")
}
}
}
Loading