Skip to content

Return Unauthorized on UnauthorizedAccessException #1

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions WebhookRelayService/Controllers/WebhookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public async Task<IActionResult> Webhook()
return Ok();
} catch (Exception ex)
{
if (ex is UnauthorizedAccessException) {
return Unauthorized();
}
_logger.LogError("Webhook error", ex);
SentrySdk.CaptureException(ex);
return StatusCode(500);
Expand Down
39 changes: 14 additions & 25 deletions WebhookRelayService/Services/WebhookService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,24 @@ public WebhookService(IWebhookUserRepository webhookUserRepository, Settings set

public async Task<string> HandleWebhook(int webhookId, Webhook webhook, string payload, string signature)
{
try
var user = await _webhookUserRepository.GetByWebhookId(webhookId);
if (user == null)
{
var user = await _webhookUserRepository.GetByWebhookId(webhookId);
if (user == null)
{
return "gone";
}

if (!_settings.SkipSignatureCheck)
await ValidateSignature(user.WebhookSecret, payload, signature);
else
_logger.LogInformation("Skipped signature check");
return "gone";
}

if (_settings.Logging)
{
_logger.LogInformation($"Notification {webhook.GetNotificationJson()}");
}
if (!_settings.SkipSignatureCheck)
await ValidateSignature(user.WebhookSecret, payload, signature);
else
_logger.LogInformation("Skipped signature check");

await PushNotificationAndHandleResult(user, webhook.GetNotificationJson());
return "ok";
}
catch (Exception ex)
if (_settings.Logging)
{
SentrySdk.CaptureException(ex);
return "error";
_logger.LogInformation($"Notification {webhook.GetNotificationJson()}");
}

await PushNotificationAndHandleResult(user, webhook.GetNotificationJson());
return "ok";
}

public async Task<int> PushNotificationAndHandleResult(WebhookUser user, string content)
Expand Down Expand Up @@ -106,10 +98,7 @@ private async Task ValidateSignature(string secret, string payload, string signa
_logger.LogError($"Secret: {secret}");
_logger.LogError($"Payload: {payload}");
}
else
{
throw new UnauthorizedAccessException();
}
throw new UnauthorizedAccessException();
}
}
}
Expand Down