gemini warn about vulnerable to Insecure Direct Object Reference #22022

Open
opened 2026-02-21 20:15:19 -05:00 by yindo · 2 comments
Owner

Originally created by @asukaminato0721 on GitHub (Feb 2, 2026).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

master

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

this is by gemini

api/controllers/console/datasets/data_source.py (160)

security-high high

The patch method is vulnerable to Insecure Direct Object Reference (IDOR). It fetches a DataSourceOauthBinding by binding_id without verifying that it belongs to the current user's tenant. An authenticated attacker could potentially enable or disable data source bindings belonging to other tenants by providing their IDs. To remediate this, ensure that the query for the binding includes a check for the current user's tenant_id.

✔️ Expected Behavior

gemini not warning

Actual Behavior

No response

Originally created by @asukaminato0721 on GitHub (Feb 2, 2026). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version master ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce this is by gemini api/controllers/console/datasets/data_source.py (160) security-high high The patch method is vulnerable to Insecure Direct Object Reference (IDOR). It fetches a DataSourceOauthBinding by binding_id without verifying that it belongs to the current user's tenant. An authenticated attacker could potentially enable or disable data source bindings belonging to other tenants by providing their IDs. To remediate this, ensure that the query for the binding includes a check for the current user's tenant_id. ### ✔️ Expected Behavior gemini not warning ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 20:15:19 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Feb 2, 2026):

Gemini flags the PATCH method as vulnerable to Insecure Direct Object Reference (IDOR) because it fetches a DataSourceOauthBinding by binding_id without checking if it belongs to the current user's tenant. This means an authenticated user could operate on bindings from other tenants just by guessing or supplying their IDs, which is a classic IDOR scenario (source).

To remediate this and silence Gemini's warning, update the query in the PATCH method to include tenant ownership verification. Use current_account_with_tenant() to get the current tenant_id, then filter by both id and tenant_id when fetching the binding. For example:

_, current_tenant_id = current_account_with_tenant()
with Session(db.engine) as session:
    data_source_binding = session.execute(
        select(DataSourceOauthBinding).filter_by(id=binding_id, tenant_id=current_tenant_id)
    ).scalar_one_or_none()

This ensures only bindings belonging to the current tenant can be enabled or disabled, eliminating the IDOR risk and aligning with best practices for multi-tenant security (source).

After making this change, test by attempting to access or modify a binding from another tenant—this should now fail with a "not found" error. Gemini should no longer report the IDOR vulnerability once tenant verification is enforced.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Feb 2, 2026): <!-- Answer --> Gemini flags the PATCH method as vulnerable to Insecure Direct Object Reference (IDOR) because it fetches a DataSourceOauthBinding by binding_id without checking if it belongs to the current user's tenant. This means an authenticated user could operate on bindings from other tenants just by guessing or supplying their IDs, which is a classic IDOR scenario [(source)](https://github.com/langgenius/dify/blob/ce2c41bbf5662f2334e5b178f1d807c62b44c20e/api/controllers/console/datasets/data_source.py#L160-L187). To remediate this and silence Gemini's warning, update the query in the PATCH method to include tenant ownership verification. Use `current_account_with_tenant()` to get the current tenant_id, then filter by both id and tenant_id when fetching the binding. For example: ```python _, current_tenant_id = current_account_with_tenant() with Session(db.engine) as session: data_source_binding = session.execute( select(DataSourceOauthBinding).filter_by(id=binding_id, tenant_id=current_tenant_id) ).scalar_one_or_none() ``` This ensures only bindings belonging to the current tenant can be enabled or disabled, eliminating the IDOR risk and aligning with best practices for multi-tenant security [(source)](https://github.com/langgenius/dify/blob/ce2c41bbf5662f2334e5b178f1d807c62b44c20e/api/controllers/console/datasets/data_source.py#L112-L187). After making this change, test by attempting to access or modify a binding from another tenant—this should now fail with a "not found" error. Gemini should no longer report the IDOR vulnerability once tenant verification is enforced. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/ff3bd939-d91c-4178-ba21-8ee256124bd5?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/ff3bd939-d91c-4178-ba21-8ee256124bd5?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/ff3bd939-d91c-4178-ba21-8ee256124bd5?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/ff3bd939-d91c-4178-ba21-8ee256124bd5?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/ff3bd939-d91c-4178-ba21-8ee256124bd5?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/ff3bd939-d91c-4178-ba21-8ee256124bd5?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/ff3bd939-d91c-4178-ba21-8ee256124bd5?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Gemini%20flags%20the%20PATCH%20method%20as%20vulnerable%20to%20Insecure%20Direct%20Object%20Reference%20%28IDOR%29%20because%20it%20fetches%20a%20DataSourceOauthBinding%20by%20binding_id%20without%20checking%20if%20it%20belongs%20to%20the%20current%20user%27s%20tenant.%20This%20means%20an%20authenticated%20user%20could%20operate%20on%20bindings%20from%20other%20tenants%20just%20by%20guessing%20or%20supplying%20their%20IDs%2C%20which%20is%20a%20classic%20IDOR%20scenario%20%5B%28source%29%5D%28https%3A//github.com/langgenius/dify/blob/ce2c41bbf5662f2334e5b178f1d807c62b44c20e/api/controllers/console/datasets/data_source.py%23L160-L187%29.%0A%0ATo%20remediate%20this%20and%20silence%20Gemini%27s%20warning%2C%20update%20the%20query%20in%20the%20PATCH%20method%20to%20include%20tenant%20ownership%20verification.%20Use%20%60current_account_with_tenant%28%29%60%20to%20get%20the%20current%20tenant_id%2C%20then%20filter%20by%20both%20id%20and%20tenant_id%20when%20fetching%20the%20binding.%20For%20example%3A%0A%0A%60%60%60python%0A_%2C%20current_tenant_id%20%3D%20current_account_with_tenant%28%29%0Awith%20Session%28db.engine%29%20as%20session%3A%0A%20%20%20%20data_source_binding%20%3D%20session.execute%28%0A%20%20%20%20%20%20%20%20select%28DataSourceOauthBinding%29.filter_by%28id%3Dbinding_id%2C%20tenant_id%3Dcurrent_tenant_id%29%0A%20%20%20%20%29.scalar_one_or_none%28%29%0A%60%60%60%0A%0AThis%20ensures%20only%20bindings%20belonging%20to%20the%20current%20tenant%20can%20be%20enabled%20or%20disabled%2C%20eliminating%20the%20IDOR%20risk%20and%20aligning%20with%20best%20practices%20for%20multi-tenant%20security%20%5B%28source%29%5D%28https%3A//github.com/langgenius/dify/blob/ce2c41bbf5662f2334e5b178f1d807c62b44c20e/api/controllers/console/datasets/data_source.py%23L112-L187%29.%0A%0AAfter%20making%20this%20change%2C%20test%20by%20attempting%20to%20access%20or%20modify%20a%20binding%20from%20another%20tenant%E2%80%94this%20should%20now%20fail%20with%20a%20%22not%20found%22%20error.%20Gemini%20should%20no%20longer%20report%20the%20IDOR%20vulnerability%20once%20tenant%20verification%20is%20enforced.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/31839)
Author
Owner

@asukaminato0721 commented on GitHub (Feb 2, 2026):

will fix it in another pr

@asukaminato0721 commented on GitHub (Feb 2, 2026): will fix it in another pr
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#22022