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

fix: Prevent circular structure serialization in events #3727

Merged
merged 3 commits into from
Jun 22, 2021
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
33 changes: 16 additions & 17 deletions packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,18 @@ export class GlobalHandlers implements Integration {
}

const client = currentHub.getClient();
const event = isPrimitive(error)
? this._eventFromIncompleteOnError(data.msg, data.url, data.line, data.column)
: this._enhanceEventWithInitialFrame(
eventFromUnknownInput(error, undefined, {
attachStacktrace: client && client.getOptions().attachStacktrace,
rejection: false,
}),
data.url,
data.line,
data.column,
);
const event =
error === undefined && isString(data.msg)
? this._eventFromIncompleteOnError(data.msg, data.url, data.line, data.column)
: this._enhanceEventWithInitialFrame(
eventFromUnknownInput(error || data.msg, undefined, {
attachStacktrace: client && client.getOptions().attachStacktrace,
rejection: false,
}),
data.url,
data.line,
data.column,
);

addExceptionMechanism(event, {
handled: false,
Expand Down Expand Up @@ -188,12 +189,10 @@ export class GlobalHandlers implements Integration {
let message = isErrorEvent(msg) ? msg.message : msg;
let name;

if (isString(message)) {
const groups = message.match(ERROR_TYPES_RE);
if (groups) {
name = groups[1];
message = groups[2];
}
const groups = message.match(ERROR_TYPES_RE);
if (groups) {
name = groups[1];
message = groups[2];
}

const event = {
Expand Down
19 changes: 19 additions & 0 deletions packages/browser/test/integration/suites/onerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,25 @@ describe("window.onerror", function() {
});
});

it("should onerror calls with non-string first argument gracefully", function() {
return runInSandbox(sandbox, function() {
window.onerror({
type: "error",
otherKey: "hi",
});
}).then(function(summary) {
assert.equal(summary.events[0].exception.values[0].type, "Error");
assert.equal(
summary.events[0].exception.values[0].value,
"Non-Error exception captured with keys: otherKey, type"
);
assert.deepEqual(summary.events[0].extra.__serialized__, {
type: "error",
otherKey: "hi",
});
});
});

it("should NOT catch an exception already caught [but rethrown] via Sentry.captureException", function() {
return runInSandbox(sandbox, function() {
try {
Expand Down