33import { context as grafastContext , lambda , object } from 'grafast' ;
44import type { GraphileConfig } from 'graphile-config' ;
55import { extendSchema , gql } from 'graphile-utils' ;
6+ import { escapeIdentifier } from 'pg' ;
67import pgQueryWithContext from 'pg-query-context' ;
78
89export interface PublicKeyChallengeConfig {
@@ -115,7 +116,7 @@ export const PublicKeySignature = (pubkey_challenge: PublicKeyChallengeConfig):
115116 await pgQueryWithContext ( {
116117 client : pgClient ,
117118 context : { role : 'anonymous' } ,
118- query : `SELECT * FROM " ${ schema } "." ${ sign_up_with_key } " ($1)` ,
119+ query : `SELECT * FROM ${ escapeIdentifier ( schema ) } . ${ escapeIdentifier ( sign_up_with_key ) } ($1)` ,
119120 variables : [ input . publicKey ] ,
120121 skipTransaction : true
121122 } ) ;
@@ -125,7 +126,7 @@ export const PublicKeySignature = (pubkey_challenge: PublicKeyChallengeConfig):
125126 } = await pgQueryWithContext ( {
126127 client : pgClient ,
127128 context : { role : 'anonymous' } ,
128- query : `SELECT * FROM " ${ schema } "." ${ sign_in_request_challenge } " ($1)` ,
129+ query : `SELECT * FROM ${ escapeIdentifier ( schema ) } . ${ escapeIdentifier ( sign_in_request_challenge ) } ($1)` ,
129130 variables : [ input . publicKey ] ,
130131 skipTransaction : true
131132 } ) ;
@@ -156,9 +157,8 @@ export const PublicKeySignature = (pubkey_challenge: PublicKeyChallengeConfig):
156157 } = await pgQueryWithContext ( {
157158 client : pgClient ,
158159 context : { role : 'anonymous' } ,
159- query : `SELECT * FROM "${ schema } "."${ sign_in_request_challenge } "($1)` ,
160- variables : [ input . publicKey ] ,
161- skipTransaction : true
160+ query : `SELECT * FROM ${ escapeIdentifier ( schema ) } .${ escapeIdentifier ( sign_in_request_challenge ) } ($1)` ,
161+ variables : [ input . publicKey ]
162162 } ) ;
163163
164164 if ( ! message ) throw new Error ( 'NO_ACCOUNT_EXISTS' ) ;
@@ -203,7 +203,7 @@ export const PublicKeySignature = (pubkey_challenge: PublicKeyChallengeConfig):
203203 } = await pgQueryWithContext ( {
204204 client : pgClient ,
205205 context : { role : 'anonymous' } ,
206- query : `SELECT * FROM " ${ schema } "." ${ sign_in_with_challenge } " ($1, $2)` ,
206+ query : `SELECT * FROM ${ escapeIdentifier ( schema ) } . ${ escapeIdentifier ( sign_in_with_challenge ) } ($1, $2)` ,
207207 variables : [ publicKey , message ] ,
208208 skipTransaction : true
209209 } ) ;
0 commit comments