← All reports

[Swift] Optionally decode IPC arguments into Swift types

Component: WebKit IPC (Swift) | 9cce7a6

Configurations/CommonBase.xcconfig

-WK_SWIFT_MEMORY_SAFETY_ERROR_FLAGS = -Werror StrictMemorySafety -Werror ForeignReferenceType -Werror RegionIsolation;
+WK_SWIFT_MEMORY_SAFETY_ERROR_FLAGS = -Werror StrictMemorySafety -Werror ForeignReferenceType -Werror RegionIsolation -Werror SendableClosureCaptures;

LayoutTests/ipc/swift-receiver-swift-types-malformed.html

+const malformedArguments = [
+ ['an unknown enum value', args => args[0] = { type: 'uint8_t', value: 3 }],
+ ['an unknown option bit', args => args[1] = { type: 'uint8_t', value: 8 }],
+ ['a bool enum that is neither 0 nor 1', args => args[2] = { type: 'uint8_t', value: 2 }],
+ ['a zero identifier', args => args[3] = { type: 'uint64_t', value: 0 }],
+ ['the hash table deleted identifier', args => args[3] = { type: 'uint64_t', value: 18446744073709551615n }],

WebKit IPC messages are declared in .messages.in files and the types they carry in .serialization.in files; Python generators turn these into C++ encoders and decoders, so the declarations act as a central, auditable map of the attack surface. Swift receivers (currently the back/forward list and IPC testing) used to get arguments already decoded into C++ types.

For a Swift-typed message, C++ now lends generated Swift an IPC::SwiftDecoder whose primitive decoders are the existing C++ ones, behind a NonEscapableBorrow that must not outlive the call. Generated Swift composes them into Swift structs, enums, OptionSets, Variants and identifiers, and returns false on malformed input so C++ marks the message invalid. Replies go through IPC::SwiftReplyEncoder. generate-serializers.py now emits GeneratedSerializers.swift for every [Swift] type; the wire format is unchanged. SendableClosureCaptures becomes a hard error.

Swift handlers no longer pay interop costs for arguments and replies they never hand back to C++. This creates a second, generated IPC decode path in privileged processes, whose validation is reimplemented in Swift rather than shared with the C++ coders.

Two decoders for one wire format means every divergence is a potential validation gap: