-
Notifications
You must be signed in to change notification settings - Fork 5
add sendPayloadChecksums config option and implement Bugsnag-Integrit… #532
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
djskinner
wants to merge
12
commits into
next
Choose a base branch
from
integrity
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+384
−30
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f998c52
add sendPayloadChecksums config option and implement Bugsnag-Integrit…
b8f5d5b
add sendPayloadChecksums config option and implement Bugsnag-Integrit…
784cdf6
Merge branch 'integrity' of github.com:bugsnag/bugsnag-js-performance…
287bf9b
add integrity e2e test
0ffe3fa
add test for integrity disabled
9860c08
add test for integrity disabled
7b46548
disable --https for mobile browser tests
d917aa0
skip integrity tests on safari 11
be449f4
try fix CDN build
5542818
try fix CDN build
55d6ae8
Merge branch 'next' into integrity
906d8c6
fix test to reset isSecureContext
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodejs 20.11.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { TextDecoder, TextEncoder } from 'node:util' | ||
import crypto from 'crypto' | ||
|
||
Object.defineProperty(window, 'crypto', { | ||
get () { | ||
return { | ||
getRandomValues: crypto.getRandomValues, | ||
subtle: crypto.webcrypto.subtle | ||
} | ||
} | ||
}) | ||
|
||
Object.defineProperty(window, 'TextEncoder', { | ||
get () { return TextEncoder } | ||
}) | ||
|
||
Object.defineProperty(window, 'TextDecoder', { | ||
get () { return TextDecoder } | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
import type { TracePayload } from '@bugsnag/core-performance' | ||
import type { JsonEvent } from '@bugsnag/core-performance/lib' | ||
import { | ||
|
@@ -14,11 +10,15 @@ import createFetchDeliveryFactory from '../lib/delivery' | |
const SENT_AT_FORMAT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/ | ||
|
||
describe('Browser Delivery', () => { | ||
it('delivers a span', async () => { | ||
const fetch = jest.fn(() => Promise.resolve({ status: 200, headers: new Headers() } as unknown as Response)) | ||
const backgroundingListener = new ControllableBackgroundingListener() | ||
const clock = new IncrementingClock('2023-01-02T00:00:00.000Z') | ||
beforeAll(() => { | ||
window.isSecureContext = true | ||
}) | ||
|
||
afterAll(() => { | ||
window.isSecureContext = false | ||
}) | ||
|
||
it('delivers a span', async () => { | ||
const deliveryPayload: TracePayload = { | ||
body: { | ||
resourceSpans: [{ | ||
|
@@ -45,8 +45,12 @@ describe('Browser Delivery', () => { | |
} | ||
} | ||
|
||
const fetch = jest.fn(() => Promise.resolve({ status: 200, headers: new Headers() } as unknown as Response)) | ||
const backgroundingListener = new ControllableBackgroundingListener() | ||
const clock = new IncrementingClock('2023-01-02T00:00:00.000Z') | ||
|
||
const deliveryFactory = createFetchDeliveryFactory(fetch, clock, backgroundingListener) | ||
const delivery = deliveryFactory('/test') | ||
const delivery = deliveryFactory('/test', true) | ||
const response = await delivery.send(deliveryPayload) | ||
|
||
expect(fetch).toHaveBeenCalledWith('/test', { | ||
|
@@ -57,7 +61,8 @@ describe('Browser Delivery', () => { | |
'Bugsnag-Api-Key': 'test-api-key', | ||
'Bugsnag-Span-Sampling': '1:1', | ||
'Content-Type': 'application/json', | ||
'Bugsnag-Sent-At': new Date(clock.timeOrigin + 1).toISOString() | ||
'Bugsnag-Sent-At': new Date(clock.timeOrigin + 1).toISOString(), | ||
'Bugsnag-Integrity': 'sha1 835f1ff603eb1be3bf91fc9716c0841e1b37ee64' | ||
} | ||
}) | ||
|
||
|
@@ -98,7 +103,7 @@ describe('Browser Delivery', () => { | |
} | ||
|
||
const deliveryFactory = createFetchDeliveryFactory(fetch, new IncrementingClock(), backgroundingListener) | ||
const delivery = deliveryFactory('/test') | ||
const delivery = deliveryFactory('/test', false) | ||
|
||
backgroundingListener.sendToBackground() | ||
|
||
|
@@ -153,7 +158,7 @@ describe('Browser Delivery', () => { | |
} | ||
|
||
const deliveryFactory = createFetchDeliveryFactory(fetch, new IncrementingClock(), backgroundingListener) | ||
const delivery = deliveryFactory('/test') | ||
const delivery = deliveryFactory('/test', false) | ||
|
||
backgroundingListener.sendToBackground() | ||
backgroundingListener.sendToForeground() | ||
|
@@ -200,7 +205,7 @@ describe('Browser Delivery', () => { | |
const backgroundingListener = new ControllableBackgroundingListener() | ||
|
||
const deliveryFactory = createFetchDeliveryFactory(fetch, new IncrementingClock(), backgroundingListener) | ||
const delivery = deliveryFactory('/test') | ||
const delivery = deliveryFactory('/test', false) | ||
const deliveryPayload: TracePayload = { | ||
body: { resourceSpans: [] }, | ||
headers: { | ||
|
@@ -238,7 +243,7 @@ describe('Browser Delivery', () => { | |
const backgroundingListener = new ControllableBackgroundingListener() | ||
|
||
const deliveryFactory = createFetchDeliveryFactory(fetch, new IncrementingClock(), backgroundingListener) | ||
const delivery = deliveryFactory('/test') | ||
const delivery = deliveryFactory('/test', false) | ||
const payload: TracePayload = { | ||
body: { resourceSpans: [] }, | ||
headers: { | ||
|
@@ -293,10 +298,119 @@ describe('Browser Delivery', () => { | |
} | ||
|
||
const deliveryFactory = createFetchDeliveryFactory(fetch, clock, backgroundingListener) | ||
const delivery = deliveryFactory('/test') | ||
const delivery = deliveryFactory('/test', false) | ||
|
||
const { state } = await delivery.send(deliveryPayload) | ||
|
||
expect(state).toBe('failure-discard') | ||
}) | ||
|
||
it('omits the bugsnag integrity header when not in a secure context', async () => { | ||
const deliveryPayload: TracePayload = { | ||
body: { | ||
resourceSpans: [{ | ||
resource: { attributes: [{ key: 'test-key', value: { stringValue: 'test-value' } }] }, | ||
scopeSpans: [{ | ||
spans: [{ | ||
name: 'test-span', | ||
kind: 1, | ||
spanId: 'test-span-id', | ||
traceId: 'test-trace-id', | ||
endTimeUnixNano: '56789', | ||
startTimeUnixNano: '12345', | ||
attributes: [{ key: 'test-span', value: { intValue: '12345' } }], | ||
droppedAttributesCount: 0, | ||
events: [] | ||
}] | ||
}] | ||
}] | ||
}, | ||
headers: { | ||
'Bugsnag-Api-Key': 'test-api-key', | ||
'Content-Type': 'application/json', | ||
'Bugsnag-Span-Sampling': '1:1' | ||
} | ||
} | ||
|
||
window.isSecureContext = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this remain There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yeah 👍 fixed |
||
const _fetch = jest.fn(() => Promise.resolve({ status: 200, headers: new Headers() } as unknown as Response)) | ||
const backgroundingListener = new ControllableBackgroundingListener() | ||
const clock = new IncrementingClock('2023-01-02T00:00:00.000Z') | ||
|
||
const deliveryFactory = createFetchDeliveryFactory(_fetch, clock, backgroundingListener) | ||
const delivery = deliveryFactory('/test', true) | ||
const response = await delivery.send(deliveryPayload) | ||
|
||
expect(_fetch).toHaveBeenCalledWith('/test', { | ||
method: 'POST', | ||
keepalive: false, | ||
body: JSON.stringify(deliveryPayload.body), | ||
headers: { | ||
'Bugsnag-Api-Key': 'test-api-key', | ||
'Bugsnag-Span-Sampling': '1:1', | ||
'Content-Type': 'application/json', | ||
'Bugsnag-Sent-At': new Date(clock.timeOrigin + 1).toISOString() | ||
} | ||
}) | ||
|
||
expect(response).toStrictEqual({ | ||
state: 'success', | ||
samplingProbability: undefined | ||
}) | ||
|
||
window.isSecureContext = true | ||
}) | ||
|
||
it('omits the bugsnag integrity header when sendPayloadChecksums is false', async () => { | ||
const deliveryPayload: TracePayload = { | ||
body: { | ||
resourceSpans: [{ | ||
resource: { attributes: [{ key: 'test-key', value: { stringValue: 'test-value' } }] }, | ||
scopeSpans: [{ | ||
spans: [{ | ||
name: 'test-span', | ||
kind: 1, | ||
spanId: 'test-span-id', | ||
traceId: 'test-trace-id', | ||
endTimeUnixNano: '56789', | ||
startTimeUnixNano: '12345', | ||
attributes: [{ key: 'test-span', value: { intValue: '12345' } }], | ||
droppedAttributesCount: 0, | ||
events: [] | ||
}] | ||
}] | ||
}] | ||
}, | ||
headers: { | ||
'Bugsnag-Api-Key': 'test-api-key', | ||
'Content-Type': 'application/json', | ||
'Bugsnag-Span-Sampling': '1:1' | ||
} | ||
} | ||
|
||
const fetch = jest.fn(() => Promise.resolve({ status: 200, headers: new Headers() } as unknown as Response)) | ||
const backgroundingListener = new ControllableBackgroundingListener() | ||
const clock = new IncrementingClock('2023-01-02T00:00:00.000Z') | ||
|
||
const deliveryFactory = createFetchDeliveryFactory(fetch, clock, backgroundingListener) | ||
const delivery = deliveryFactory('/test', false) | ||
const response = await delivery.send(deliveryPayload) | ||
|
||
expect(fetch).toHaveBeenCalledWith('/test', { | ||
method: 'POST', | ||
keepalive: false, | ||
body: JSON.stringify(deliveryPayload.body), | ||
headers: { | ||
'Bugsnag-Api-Key': 'test-api-key', | ||
'Bugsnag-Span-Sampling': '1:1', | ||
'Content-Type': 'application/json', | ||
'Bugsnag-Sent-At': new Date(clock.timeOrigin + 1).toISOString() | ||
} | ||
}) | ||
|
||
expect(response).toStrictEqual({ | ||
state: 'success', | ||
samplingProbability: undefined | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not keen on this but not sure of a better way. We need to work out what config options the user passed in to determine the behaviour.
const configuration = validateConfig<S, C>(config, options.schema)
does more than just validate, it creates a config with all values set based on the schema, using default values if not supplied.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right now this is the place we're performing similar manipulation on the configuration, perhaps we could refactor the validation to include this, possibly separating out validation and 'cleaning' but I think for now this is fine