Skip to content

Commit fd6189c

Browse files
authored
Merge pull request #48 from rubberduck-vba/webhook
log warning if secret is not found
2 parents ac64777 + fb39edd commit fd6189c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

rubberduckvba.Server/WebhookSignatureValidationService.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace rubberduckvba.Server;
77

8-
public class WebhookSignatureValidationService(ConfigurationOptions configuration)
8+
public class WebhookSignatureValidationService(ConfigurationOptions configuration, ILogger<WebhookSignatureValidationService> logger)
99
{
1010
public bool Validate(
1111
string payload,
@@ -64,8 +64,13 @@ private bool IsValidSignature(string? signature, string payload)
6464
}
6565

6666
var secret = configuration.GitHubOptions.Value.WebhookToken;
67-
var secretBytes = Encoding.UTF8.GetBytes(secret);
67+
if (string.IsNullOrWhiteSpace(secret))
68+
{
69+
logger.LogWarning("Webhook secret was not found; signature will not be validated.");
70+
return false;
71+
}
6872

73+
var secretBytes = Encoding.UTF8.GetBytes(secret);
6974
var payloadBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(JsonConvert.DeserializeObject(payload)));
7075

7176
using var digest = new HMACSHA256(secretBytes);

0 commit comments

Comments
 (0)