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

api: prevent null bytes in keystroke lines from causing db errors #43

Merged
merged 1 commit into from
Sep 22, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension CreateKeystrokeLines: Resolver {
KeystrokeLine(
userDeviceId: userDevice.id,
appName: input.appName,
line: input.line,
line: input.line.replacingOccurrences(of: "\0", with: "\u{FFFD}"),
filterSuspended: input.filterSuspended ?? false,
createdAt: input.time
)
Expand Down
19 changes: 19 additions & 0 deletions api/Tests/ApiTests/MacappPairResolvers/MacAppResolverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ final class MacAppResolverTests: ApiTestCase {
expect(inserted.createdAt).toEqual(.epoch)
}

func testInsertKeystrokeLineWithNullByte() async throws {
let user = try await Entities.user().withDevice()
let (uuid, _) = mockUUIDs()

let output = try await CreateKeystrokeLines.resolve(
with: [.init(
appName: "Xcode",
line: "Hello\0World", // <-- causes postgres to choke
filterSuspended: false,
time: .epoch
)],
in: context(user)
)

expect(output).toEqual(.success)
let inserted = try await Current.db.find(KeystrokeLine.Id(uuid))
expect(inserted.line).toEqual("Hello�World")
}

func testCreateUnlockRequests_v2() async throws {
let user = try await Entities.user().withDevice()
let blocked = CreateUnlockRequests_v2.Input.BlockedRequest(
Expand Down