From d66c2136672d0ab91b686fce2bf2d5fffeb50b6a Mon Sep 17 00:00:00 2001 From: Richard Elms Date: Wed, 8 May 2024 21:59:26 +0200 Subject: [PATCH 1/2] header ready for testing --- features/support/env.rb | 2 +- src/BugsnagUnity/Delivery.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/features/support/env.rb b/features/support/env.rb index 7f55fd1b7..dc994e5f3 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -64,7 +64,7 @@ BeforeAll do $api_key = 'a35a2a72bd230ac0aa0f52715bbdc6aa' - Maze.config.enforce_bugsnag_integrity = false + Maze.config.enforce_bugsnag_integrity = true if Maze.config.os&.downcase == 'macos' # The default macOS Crash Reporter "#{app_name} quit unexpectedly" alert grabs focus which can cause tests to flake. diff --git a/src/BugsnagUnity/Delivery.cs b/src/BugsnagUnity/Delivery.cs index 2057f387f..55b8601fd 100644 --- a/src/BugsnagUnity/Delivery.cs +++ b/src/BugsnagUnity/Delivery.cs @@ -9,6 +9,7 @@ using BugsnagUnity.Payload; using UnityEngine; using UnityEngine.Networking; +using System.Security.Cryptography; namespace BugsnagUnity { @@ -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); @@ -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 @event, int bytesToRemove) { var breadcrumbsList = (@event[EVENT_KEY_BREADCRUMBS] as Dictionary[]).ToList(); From 8fa9913903b2b17fb3ba8d85cabc18e6f4971836 Mon Sep 17 00:00:00 2001 From: Richard Elms Date: Fri, 10 May 2024 09:01:28 +0200 Subject: [PATCH 2/2] env update --- features/support/env.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/features/support/env.rb b/features/support/env.rb index dc994e5f3..d3ac761bf 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -64,8 +64,6 @@ BeforeAll do $api_key = 'a35a2a72bd230ac0aa0f52715bbdc6aa' - Maze.config.enforce_bugsnag_integrity = true - 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.