Provider IDs with a trailing newline are silently accepted and propagated

Open Beginner friendly
#46,875 1 comment 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Batianxieshen1 is already working on this.

Since Nov 21, 2026.

  • #46878 by @Batianxieshen1 — open
  • #46879 by @mintcoder-cn — closed without merging

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start in api/models/provider_ids.py, in GenericProviderID.__init__, where the two ^...$ patterns are checked with re.match. The repro is in the issue: GenericProviderID("langgenius/openai/gpt\n") and GenericProviderID("openai\n") should raise ValueError("Invalid plugin id ...") but currently do not. Run those two cases, and the subclasses that share the constructor, to confirm the fix.

Written by the indexing model from the issue text.

Description

Describe the bug

GenericProviderID.__init__ in api/models/provider_ids.py validates a plugin
/provider identifier with two regular expressions that are both anchored with
^...$ and matched with re.match. In Python, $ matches at the end of the
string or just before a trailing newline, so an identifier ending in \n
passes both checks. value.split("/") then keeps the newline inside the
parsed segments.

The subclasses (ModelProviderID, ToolProviderID, DatasourceProviderID,
TriggerProviderID) share this constructor, so every typed provider ID is
affected.

Real user path

Provider identifier strings reach GenericProviderID from user-facing
inputs. Console API endpoints build the ID directly from a request parameter;
for example api/controllers/console/workspace/tool_providers.py calls
ToolProviderID(provider) inside a get(..., provider: str) handler and then
uses tool_provider.plugin_id and tool_provider.provider_name for the
downstream lookup. api/core/plugin/provider_identity.py (used for
plugin-daemon transport) also rebuilds an ID as
GenericProviderID(f"{normalized_plugin_id}/{provider_id.provider_name}") and
returns normalized_provider_id.plugin_id.

A value read from a file, an environment variable, a DSL import or an API
payload can retain a trailing newline (for instance a provider name read from
a line-oriented configuration without stripping). Such a value currently
passes validation, and the newline becomes part of organization,
plugin_name or provider_name. The resulting plugin_id and the lookups
built from it no longer match the intended provider, so the request fails to
resolve the plugin/provider instead of reporting an invalid identifier.

To reproduce
from models.provider_ids import GenericProviderID

p = GenericProviderID("langgenius/openai/gpt\n")
assert p.provider_name == "gpt\n"

q = GenericProviderID("openai\n")
assert q.plugin_name == "openai\n"
assert q.provider_name == "openai\n"
Expected behavior

An identifier containing any character outside [a-z0-9_-] and the /
separators - including a trailing newline - should be rejected with
ValueError("Invalid plugin id ..."), in line with the validation intent of
the two regular expressions.

Actual behavior

Both checks use re.match(r"^...$", value). re.match accepts the value
because $ also matches immediately before a trailing newline, so no
exception is raised and the polluted segments are stored.

Environment
  • dify origin/main (63069f5f)
  • Python 3.11+
Dominant language
Python
Stars
162k
Forks
25.6k
Avg merge
15h 9m
Merged PRs (30d)
606

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from langgenius/dify

All issues in langgenius/dify

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.