Skip to content

Commit 2507c5e

Browse files
committed
Allow String to be used for table and column names in COPY FROM
1 parent 29a88bc commit 2507c5e

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
@@ -128,9 +128,12 @@ public struct PostgresCopyFromFormat: Sendable {
128128
///
129129
/// An empty `columns` array signifies that no columns should be specified in the query and that all columns will be
130130
/// copied by the caller.
131+
///
132+
/// - Important: The table and column names are inserted into the `COPY FROM` query as passed and might thus be
133+
/// susceptible to SQL injection. Ensure no untrusted data is contained in these strings.
131134
private func buildCopyFromQuery(
132-
table: StaticString,
133-
columns: [StaticString] = [],
135+
table: String,
136+
columns: [String] = [],
134137
format: PostgresCopyFromFormat
135138
) -> PostgresQuery {
136139
var query = """
@@ -170,11 +173,11 @@ extension PostgresConnection {
170173
/// Throw an error from the closure to fail the data transfer. The error thrown by the closure will be rethrown
171174
/// by the `copyFrom` function.
172175
///
173-
/// - Note: The table and column names are inserted into the SQL query verbatim. They are forced to be compile-time
174-
/// specified to avoid runtime SQL injection attacks.
176+
/// - Important: The table and column names are inserted into the `COPY FROM` query as passed and might thus be
177+
/// susceptible to SQL injection. Ensure no untrusted data is contained in these strings.
175178
public func copyFrom(
176-
table: StaticString,
177-
columns: [StaticString] = [],
179+
table: String,
180+
columns: [String] = [],
178181
format: PostgresCopyFromFormat = .text(.init()),
179182
logger: Logger,
180183
isolation: isolated (any Actor)? = #isolation,

Tests/PostgresNIOTests/New/PostgresConnectionTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,8 +993,8 @@ import Synchronization
993993
/// and is now expecting a `Sync` to return back to the idle state. The closure may call the `cancelCopyFrom`
994994
/// closure that is passed to it to cancel the COPY operation.
995995
private func expectCopyFrom(
996-
table: StaticString = "copy_table",
997-
columns: [StaticString] = ["id", "name"],
996+
table: String = "copy_table",
997+
columns: [String] = ["id", "name"],
998998
format: PostgresCopyFromFormat = .text(.init()),
999999
writeData: @escaping @Sendable (PostgresCopyFromWriter) async throws -> Void,
10001000
validateCopyFromError: (@Sendable (any Error) -> Void)? = nil,

0 commit comments

Comments
 (0)