Skip to content

Commit 1602d85

Browse files
committed
Allow String to be used for table and column names in COPY FROM
1 parent 568d258 commit 1602d85

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Sources/PostgresNIO/Connection/PostgresConnection+CopyFrom.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,12 @@ public struct PostgresCopyFromFormat: Sendable {
131131
///
132132
/// An empty `columns` array signifies that no columns should be specified in the query and that all columns will be
133133
/// copied by the caller.
134+
///
135+
/// - Important: The table and column names are inserted into the `COPY FROM` query as passed and might thus be
136+
/// susceptible to SQL injection. Ensure no untrusted data is contained in these strings.
134137
private func buildCopyFromQuery(
135-
table: StaticString,
136-
columns: [StaticString] = [],
138+
table: String,
139+
columns: [String] = [],
137140
format: PostgresCopyFromFormat
138141
) -> PostgresQuery {
139142
var query = """
@@ -173,11 +176,11 @@ extension PostgresConnection {
173176
/// Throw an error from the closure to fail the data transfer. The error thrown by the closure will be rethrown
174177
/// by the `copyFrom` function.
175178
///
176-
/// - Note: The table and column names are inserted into the SQL query verbatim. They are forced to be compile-time
177-
/// specified to avoid runtime SQL injection attacks.
179+
/// - Important: The table and column names are inserted into the `COPY FROM` query as passed and might thus be
180+
/// susceptible to SQL injection. Ensure no untrusted data is contained in these strings.
178181
public func copyFrom(
179-
table: StaticString,
180-
columns: [StaticString] = [],
182+
table: String,
183+
columns: [String] = [],
181184
format: PostgresCopyFromFormat = .text(.init()),
182185
logger: Logger,
183186
isolation: isolated (any Actor)? = #isolation,

Tests/PostgresNIOTests/New/PostgresConnectionTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,8 +966,8 @@ class PostgresConnectionTests: XCTestCase {
966966
/// and is now expecting a `Sync` to return back to the idle state. The closure may call the `cancelCopyFrom`
967967
/// closure that is passed to it to cancel the COPY operation.
968968
private func assertCopyFrom(
969-
table: StaticString = "copy_table",
970-
columns: [StaticString] = ["id", "name"],
969+
table: String = "copy_table",
970+
columns: [String] = ["id", "name"],
971971
format: PostgresCopyFromFormat = .text(.init()),
972972
writeData: @escaping @Sendable (PostgresCopyFromWriter) async throws -> Void,
973973
validateCopyFromError: (@Sendable (any Error) -> Void)? = nil,

0 commit comments

Comments
 (0)