Skip to content

🛡️ Sentinel: [HIGH] Fix authorization bypass in database row mutation APIs#483

Draft
Dexploarer wants to merge 1 commit into
mainfrom
sentinel-fix-database-auth-bypass-2888632438088747809
Draft

🛡️ Sentinel: [HIGH] Fix authorization bypass in database row mutation APIs#483
Dexploarer wants to merge 1 commit into
mainfrom
sentinel-fix-database-auth-bypass-2888632438088747809

Conversation

@Dexploarer

Copy link
Copy Markdown
Owner

🚨 Severity: HIGH
💡 Vulnerability: Authorization bypass in database API. The PUT and DELETE endpoints for modifying database rows did not verify that the target table was a legitimate user-facing base table using the assertTableExists check.
🎯 Impact: An attacker could potentially modify or delete rows in arbitrary tables, including internal system tables, by manually crafting a request to /api/database/tables/:table/rows with an unauthorized or internal table name.
🔧 Fix: Added await assertTableExists(runtime, tableName) to handleUpdateRow and handleDeleteRow, returning a 404 error if the table is invalid, mirroring the behavior of handleInsertRow and handleGetRows.
✅ Verification: Local tests pass. Ran bun run test src/api/database.security.test.ts test/database-api.e2e.test.ts to ensure core API flow and security tests remain green.


PR created automatically by Jules for task 2888632438088747809 started by @Dexploarer

This patch adds `assertTableExists` checks to the `PUT` (handleUpdateRow)
and `DELETE` (handleDeleteRow) endpoints in the database API. Previously,
these endpoints used the raw tableName path parameter in raw SQL strings,
which constituted an authorization bypass because malicious users could
theoretically mutate arbitrary or internal tables. Now, update and
delete mutations use the exact same validation mechanism as inserts
and reads.
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Apr 25, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5e30fcdd-fd23-4755-90f2-b77cf9aaff19

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sentinel-fix-database-auth-bypass-2888632438088747809

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread src/api/database.ts
Comment on lines 970 to 980
return;
}

if (!(await assertTableExists(runtime, tableName))) {
sendJsonError(res, `Table "${tableName}" not found`, 404);
return;
}

const setClauses = Object.entries(body.data).map(([col, val]) =>
sqlAssign(col, val),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security: Risk of SQL Injection in Update Handler

The code constructs SQL SET and WHERE clauses for the UPDATE statement by directly interpolating user-supplied data using custom helpers (sqlAssign, sqlPredicate). Unless these helpers are proven to be robust against all forms of SQL injection, this approach is highly risky. Attackers could potentially craft input that bypasses escaping and executes arbitrary SQL.

Recommendation:
Use parameterized queries provided by your database library or ORM instead of manual string interpolation. For example, with Drizzle or pg, use placeholders and pass values as parameters to ensure safe query execution.

Example (conceptual):

await db.execute('UPDATE table SET col1 = $1 WHERE col2 = $2', [val1, val2]);

Comment thread src/api/database.ts
Comment on lines 1021 to 1031
return;
}

if (!(await assertTableExists(runtime, tableName))) {
sendJsonError(res, `Table "${tableName}" not found`, 404);
return;
}

const whereClauses = Object.entries(body.where).map(([col, val]) =>
sqlPredicate(col, val),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security: Risk of SQL Injection in Delete Handler

The construction of the WHERE clause for the DELETE statement uses direct mapping of user input via sqlPredicate, which may not be sufficient to prevent SQL injection. This is a critical security vulnerability if the helper does not fully sanitize all possible input cases.

Recommendation:
Switch to parameterized queries for all user-supplied data in SQL statements. Avoid manual string construction for SQL commands. Use the parameterization features of your database adapter to ensure all values are safely escaped and injected.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an authorization bypass vulnerability by implementing table existence checks in the update and delete row endpoints, ensuring that operations are restricted to valid user tables. It also adds a corresponding entry to the sentinel log documenting the vulnerability and its prevention. The review feedback suggests optimizing these handlers by moving the existence checks before the request body parsing to follow a fail-fast pattern and improve resource efficiency.

Comment thread src/api/database.ts
Comment on lines +973 to +976
if (!(await assertTableExists(runtime, tableName))) {
sendJsonError(res, `Table "${tableName}" not found`, 404);
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While adding the assertTableExists check correctly addresses the authorization bypass, its placement after readJsonBody is less than optimal. Moving this check to the very beginning of the function (before parsing the request body) would follow the 'fail-fast' principle, avoiding unnecessary resource consumption (CPU/memory for JSON parsing) when the target table does not exist. This would also align with the implementation in handleGetRows.

Comment thread src/api/database.ts
Comment on lines +1024 to +1027
if (!(await assertTableExists(runtime, tableName))) {
sendJsonError(res, `Table "${tableName}" not found`, 404);
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to handleUpdateRow, the assertTableExists check should ideally be performed at the start of the function, before readJsonBody. This prevents the server from processing potentially large or malformed request bodies for non-existent or unauthorized tables, improving efficiency and DoS resilience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant