Skip to content

Commit 339f500

Browse files
updated: grapql query to remove sql injection problem
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 4020adb commit 339f500

File tree

1 file changed

+4
-3
lines changed
  • tutorial/markdown/nodejs/dataApi-appsync-tutorial

1 file changed

+4
-3
lines changed

tutorial/markdown/nodejs/dataApi-appsync-tutorial/tutorial.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export function request(ctx) {
200200

201201
// Construct a SQL++ query to filter hotels by city
202202
// The query_context below lets us use "hotel" instead of "travel-sample.inventory.hotel"
203-
const sql_query = `SELECT c.* FROM ${collection} AS c WHERE city = \"${city}\"`;
203+
const sql_query = `SELECT c.* FROM ${collection} AS c WHERE city = $city`;
204204

205205
// Build the HTTP request object for the Data API Query Service
206206
const requestObject = {
@@ -212,11 +212,12 @@ export function request(ctx) {
212212
'Content-Type': 'application/json',
213213
'Authorization': auth // Dynamic Basic auth per request
214214
},
215-
body: {
215+
body: JSON.stringify({
216216
query_context: `default:${bucket}.${scope}`, // Namespace shortcut
217217
statement: sql_query, // The SQL++ query
218+
args: { city: city }, // Pass parameters securely
218219
timeout: '30m' // Query timeout (generous for demo)
219-
}
220+
})
220221
}
221222
};
222223
return requestObject;

0 commit comments

Comments
 (0)