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

PLAT-12109 add bugsnag integity header #797

Merged
merged 2 commits into from
May 10, 2024
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
2 changes: 0 additions & 2 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@

BeforeAll do
$api_key = 'a35a2a72bd230ac0aa0f52715bbdc6aa'
Maze.config.enforce_bugsnag_integrity = false

if Maze.config.os&.downcase == 'macos'
# The default macOS Crash Reporter "#{app_name} quit unexpectedly" alert grabs focus which can cause tests to flake.
# This option, which appears to have been introduced in macOS 10.11, displays a notification instead of the alert.
Expand Down
17 changes: 17 additions & 0 deletions src/BugsnagUnity/Delivery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using BugsnagUnity.Payload;
using UnityEngine;
using UnityEngine.Networking;
using System.Security.Cryptography;

namespace BugsnagUnity
{
Expand Down Expand Up @@ -187,6 +188,8 @@ IEnumerator PushToServer(IPayload payload)
{
req.SetRequestHeader("Content-Type", "application/json");
req.SetRequestHeader("Bugsnag-Sent-At", DateTimeOffset.Now.ToString("o", CultureInfo.InvariantCulture));
req.SetRequestHeader("Bugsnag-Integrity", "sha1 " + Hash(body));

foreach (var header in payload.Headers)
{
req.SetRequestHeader(header.Key, header.Value);
Expand Down Expand Up @@ -278,6 +281,20 @@ private byte[] PrepareEventBodySimple(IPayload payload)
return serialisedPayload;
}

private string Hash(byte[] input)
{
using (SHA1Managed sha1 = new SHA1Managed())
{
var hash = sha1.ComputeHash(input);
var sb = new StringBuilder(hash.Length * 2);
foreach (byte b in hash)
{
sb.Append(b.ToString("x2"));
}
return sb.ToString();
}
}

private bool TruncateBreadcrumbs(Dictionary<string, object> @event, int bytesToRemove)
{
var breadcrumbsList = (@event[EVENT_KEY_BREADCRUMBS] as Dictionary<string, object>[]).ToList();
Expand Down
Loading