Skip to content

Commit f000958

Browse files
committed
Avoid potential SQL injection.
1 parent b10893d commit f000958

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/powersync/lib/src/bucket_storage.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ class BucketStorage {
263263
}
264264

265265
await tx.execute(
266-
"UPDATE ps_buckets SET target_op = ? WHERE name='\$local'", [opId]);
266+
"UPDATE ps_buckets SET target_op = CAST(? as INTEGER) WHERE name='\$local'",
267+
[opId]);
267268

268269
return true;
269270
});
@@ -300,7 +301,8 @@ class BucketStorage {
300301
if (writeCheckpoint != null &&
301302
(await tx.execute('SELECT 1 FROM ps_crud LIMIT 1')).isEmpty) {
302303
await tx.execute(
303-
'UPDATE ps_buckets SET target_op = $writeCheckpoint WHERE name=\'\$local\'');
304+
'UPDATE ps_buckets SET target_op = CAST(? as INTEGER) WHERE name=\'\$local\'',
305+
[writeCheckpoint]);
304306
} else {
305307
await tx.execute(
306308
'UPDATE ps_buckets SET target_op = $maxOpId WHERE name=\'\$local\'');

packages/powersync/lib/src/database/powersync_db_mixin.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
310310
if (writeCheckpoint != null &&
311311
await db.getOptional('SELECT 1 FROM ps_crud LIMIT 1') == null) {
312312
await db.execute(
313-
'UPDATE ps_buckets SET target_op = $writeCheckpoint WHERE name=\'\$local\'');
313+
'UPDATE ps_buckets SET target_op = CAST(? as INTEGER) WHERE name=\'\$local\'',
314+
[writeCheckpoint]);
314315
} else {
315316
await db.execute(
316317
'UPDATE ps_buckets SET target_op = $maxOpId WHERE name=\'\$local\'');
@@ -361,7 +362,8 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
361362
await db.getOptional('SELECT 1 FROM ps_crud LIMIT 1') ==
362363
null) {
363364
await db.execute(
364-
'UPDATE ps_buckets SET target_op = $writeCheckpoint WHERE name=\'\$local\'');
365+
'UPDATE ps_buckets SET target_op = CAST(? as INTEGER) WHERE name=\'\$local\'',
366+
[writeCheckpoint]);
365367
} else {
366368
await db.execute(
367369
'UPDATE ps_buckets SET target_op = $maxOpId WHERE name=\'\$local\'');

0 commit comments

Comments
 (0)