Malformed JSON creates an unrestricted dataset API key
Self Checks
- [x] I have read the Contributing Guide and Language Policy.
- [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [x] I have searched for existing issues search for existing 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
main (0900748cf26d5653fe1b4bde18b98010d717b48a)
Cloud or Self Hosted
Self Hosted (Source)
Steps to reproduce
As a workspace owner/admin, send a non-empty invalid or non-object JSON body to the dataset API-key creation endpoint. For example:
POST /console/api/datasets/api-keys
Content-Type: application/json
{
The same issue occurs with JSON [], null, false, 0, or a string. On current main (0900748cf26d5653fe1b4bde18b98010d717b48a), each request returns 200 and invokes key creation.
✔️ Expected Behavior
Reject malformed JSON and non-object JSON with a client error before creating an API key. Preserve the endpoint's existing handling of a genuinely empty body for compatibility.
❌ Actual Behavior
The endpoint uses request.get_json(silent=True) or {}. Parse failures and falsy JSON values therefore become {}. _id_list() also treats a non-dictionary payload as if both scope lists were absent. The key service persists a key with no binding rows, and dataset_api_key_bindings defines no rows as unrestricted access to every knowledge base in the workspace. The API then returns the newly created token as a successful response.
Because this report concerns an unexpectedly unrestricted credential, please send it through Dify’s private security advisory form, including the pinned commit and reproduction above. Dify’s security policy directs potential vulnerabilities there for maintainer review and coordinated follow-up, and asks that additional vulnerability details not be disclosed publicly before review and an appropriate fix or mitigation. [1]
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
Thanks for reporting this, @mikamikasuki. I traced it to request validation in the key creation handler. I’m working on a fix that rejects invalid requests before a key is created and preserves compatibility for clients that send an empty body.