mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
fix: encode URI components in fetch requests to prevent errors with special characters
This commit is contained in:
parent
c329a46e33
commit
26ce83f935
@ -50,7 +50,7 @@ async function rawCallReducer(token: string, reducer: string, args: unknown[]):
|
||||
const base = httpBase();
|
||||
if (!base) throw new StackAssertionError("SpacetimeDB not configured");
|
||||
const dbName = getEnvVariable("STACK_SPACETIMEDB_DB_NAME");
|
||||
const res = await fetch(`${base}/v1/database/${dbName}/call/${reducer}`, {
|
||||
const res = await fetch(`${base}/v1/database/${encodeURIComponent(dbName)}/call/${encodeURIComponent(reducer)}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@ -105,7 +105,7 @@ export async function callSql<T = Record<string, unknown>>(sql: string): Promise
|
||||
const base = httpBase();
|
||||
if (!base) return [];
|
||||
const dbName = getEnvVariable("STACK_SPACETIMEDB_DB_NAME");
|
||||
const res = await fetch(`${base}/v1/database/${dbName}/sql`, {
|
||||
const res = await fetch(`${base}/v1/database/${encodeURIComponent(dbName)}/sql`, {
|
||||
method: "POST",
|
||||
headers: { "Authorization": `Bearer ${token}` },
|
||||
body: sql,
|
||||
|
||||
@ -74,7 +74,7 @@ export async function callReducer(
|
||||
args: unknown[],
|
||||
): Promise<ReducerCallResult> {
|
||||
const { baseUrl, dbName } = getSpacetimedbConfig();
|
||||
const res = await fetch(`${baseUrl}/v1/database/${dbName}/call/${reducer}`, {
|
||||
const res = await fetch(`${baseUrl}/v1/database/${encodeURIComponent(dbName)}/call/${encodeURIComponent(reducer)}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@ -113,7 +113,7 @@ export async function findCorrelationIdByQuestion(
|
||||
|
||||
export async function sqlQuery(token: string, sql: string): Promise<SqlQueryResult> {
|
||||
const { baseUrl, dbName } = getSpacetimedbConfig();
|
||||
const res = await fetch(`${baseUrl}/v1/database/${dbName}/sql`, {
|
||||
const res = await fetch(`${baseUrl}/v1/database/${encodeURIComponent(dbName)}/sql`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "text/plain",
|
||||
|
||||
@ -90,7 +90,7 @@ async function probeToken(spacetimeHttpUrl, dbName, token) {
|
||||
try {
|
||||
// Cheapest valid request: a SQL query that the module owner / any identity
|
||||
// can run. Returns HTTP 200 if token signature is valid, 401 if not.
|
||||
const res = await fetch(`${spacetimeHttpUrl}/v1/database/${dbName}/sql`, {
|
||||
const res = await fetch(`${spacetimeHttpUrl}/v1/database/${encodeURIComponent(dbName)}/sql`, {
|
||||
method: "POST",
|
||||
headers: { "Authorization": `Bearer ${token}` },
|
||||
body: "SELECT 1",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user