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: sanitize span data #1963

Merged
merged 6 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- Properly sanitize the event context and SDK information (#1943)
- Don't send error 429 as `network_error` (#1957)
- Sanitize SentrySpan data and tags (#1963)
kevinrenskers marked this conversation as resolved.
Show resolved Hide resolved

## 7.20.0

Expand Down
5 changes: 3 additions & 2 deletions Sources/Sentry/SentrySpan.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "SentrySpan.h"
#import "NSDate+SentryExtras.h"
#import "NSDictionary+SentrySanitize.h"
#import "SentryCurrentDate.h"
#import "SentryNoOpSpan.h"
#import "SentryTraceHeader.h"
Expand Down Expand Up @@ -130,15 +131,15 @@ - (NSDictionary *)serialize

@synchronized(_data) {
if (_data.count > 0) {
mutableDictionary[@"data"] = _data.copy;
mutableDictionary[@"data"] = [_data.copy sentry_sanitize];
}
}

@synchronized(_tags) {
if (_tags.count > 0) {
NSMutableDictionary *tags = _context.tags.mutableCopy;
[tags addEntriesFromDictionary:_tags.copy];
mutableDictionary[@"tags"] = tags;
mutableDictionary[@"tags"] = [tags sentry_sanitize];
kevinrenskers marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
5 changes: 3 additions & 2 deletions Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "SentryTracer.h"
#import "NSDictionary+SentrySanitize.h"
#import "PrivateSentrySDKOnly.h"
#import "SentryAppStartMeasurement.h"
#import "SentryClient.h"
Expand Down Expand Up @@ -685,7 +686,7 @@ - (NSDictionary *)serialize
[mutableDictionary[@"data"] isKindOfClass:NSDictionary.class]) {
[data addEntriesFromDictionary:mutableDictionary[@"data"]];
}
mutableDictionary[@"data"] = data;
mutableDictionary[@"data"] = [data sentry_sanitize];
}
}

Expand All @@ -696,7 +697,7 @@ - (NSDictionary *)serialize
[mutableDictionary[@"tags"] isKindOfClass:NSDictionary.class]) {
[tags addEntriesFromDictionary:mutableDictionary[@"tags"]];
}
mutableDictionary[@"tags"] = tags;
mutableDictionary[@"tags"] = [tags sentry_sanitize];
kevinrenskers marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
20 changes: 20 additions & 0 deletions Tests/SentryTests/Transaction/SentrySpanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ class SentrySpanTests: XCTestCase {
XCTAssertEqual((serialization["data"] as! Dictionary)[fixture.extraKey], fixture.extraValue)
XCTAssertEqual((serialization["tags"] as! Dictionary)[fixture.extraKey], fixture.extraValue)
}

func testSanitizeData() {
let span = fixture.getSut()

span.setExtra(value: Date(timeIntervalSince1970: 10), key: "date")
span.finish()

let serialization = span.serialize()
XCTAssertEqual((serialization["data"] as! Dictionary)["date"], "1970-01-01T00:00:10.000Z")
}

func testSanitizeDataSpan() {
let span = SentrySpan(transaction: fixture.getSut() as! SentryTracer, context: SpanContext(operation: "test"))

span.setExtra(value: Date(timeIntervalSince1970: 10), key: "date")
span.finish()

let serialization = span.serialize()
XCTAssertEqual((serialization["data"] as! Dictionary)["date"], "1970-01-01T00:00:10.000Z")
}

func testSerialization_WithNoDataAndTag() {
let span = fixture.getSut()
Expand Down