Skip to content

fix: use constant-time comparison for API key validation#33986

Open
xr843 wants to merge 4 commits intolanggenius:mainfrom
xr843:fix/constant-time-api-key-compare-v3
Open

fix: use constant-time comparison for API key validation#33986
xr843 wants to merge 4 commits intolanggenius:mainfrom
xr843:fix/constant-time-api-key-compare-v3

Conversation

@xr843
Copy link
Copy Markdown
Contributor

@xr843 xr843 commented Mar 24, 2026

Summary

  • Replace == with hmac.compare_digest() for API key and secret comparisons to prevent timing attacks
  • Add tenant_id check in DataSourceOauthBinding queries to prevent IDOR vulnerabilities
  • Add test to verify tenant_id scoping in data source patch operations

Rebased on latest main to resolve CI failures from #33858 (which were caused by upstream test issues, now fixed in #33896 and #33899).

Supersedes #33858.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-24 00:08:55.984484758 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-24 00:08:47.136528613 +0000
@@ -21,9 +21,9 @@
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
    --> controllers/console/human_input_form.py:190:70
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
-  --> controllers/console/init_validate.py:31:2
+  --> controllers/console/init_validate.py:32:2
 ERROR Object of class `MissingRouter` has no attribute `post` [missing-attribute]
-  --> controllers/console/init_validate.py:44:2
+  --> controllers/console/init_validate.py:45:2
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
   --> controllers/console/ping.py:10:2
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-24 00:11:06.123580148 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-24 00:10:55.856481113 +0000
@@ -21,9 +21,9 @@
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
    --> controllers/console/human_input_form.py:190:70
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
-  --> controllers/console/init_validate.py:31:2
+  --> controllers/console/init_validate.py:32:2
 ERROR Object of class `MissingRouter` has no attribute `post` [missing-attribute]
-  --> controllers/console/init_validate.py:44:2
+  --> controllers/console/init_validate.py:45:2
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
   --> controllers/console/ping.py:10:2
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]

- data_source.py: scope patch() query by tenant_id to prevent
  cross-tenant data source binding access (IDOR vulnerability)
- test_auth_wraps.py: update mock to match db.session.query() API
  instead of db.session.get()

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@xr843 xr843 requested a review from JohnJyong as a code owner March 28, 2026 07:15
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-28 07:16:39.949555767 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-28 07:16:29.880518904 +0000
@@ -11,9 +11,9 @@
 ERROR Argument `str | None` is not assignable to parameter `language` with type `str` in function `services.account_service.AccountService.send_email_register_email` [bad-argument-type]
   --> controllers/console/auth/email_register.py:78:108
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
-  --> controllers/console/init_validate.py:31:2
+  --> controllers/console/init_validate.py:32:2
 ERROR Object of class `MissingRouter` has no attribute `post` [missing-attribute]
-  --> controllers/console/init_validate.py:44:2
+  --> controllers/console/init_validate.py:45:2
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
   --> controllers/console/ping.py:10:2
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]

@xr843
Copy link
Copy Markdown
Contributor Author

xr843 commented Mar 28, 2026

Hi team, gentle ping on this PR. It replaces direct string comparison of API keys with hmac.compare_digest(), which prevents timing side-channel attacks that could allow API key enumeration. Happy to make any adjustments if needed. Thanks for your time!

@asukaminato0721
Copy link
Copy Markdown
Contributor

fix conflict

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

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants