apache / apache/shenyu

[BUG] DefaultShenyuContextBuilder NPE on client-supplied or unknown rpc_type — no null-check on decorator lookup

Open
#6,629 1 comment 0 reactions 0 assignees View on GitHub
priority: high type: bug
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

- Severity: High
- Location:
`shenyu-plugin/shenyu-plugin-global/src/main/java/org/apache/shenyu/plugin/global/DefaultShenyuContextBuilder.java:62` (`decoratorMap.get(buildData.getLeft()).decorator(...)`); trigger at `:68` (`rpc_type` request header)
-
Description:
`build()` does `decoratorMap.get(buildData.getLeft()).decorator(...)` with no null guard. `buildData.getLeft()` is the rpc type string. `buildData` line 68 reads `headers.getFirst("rpc_type")` directly from the incoming HTTP request. A client sending `rpc_type: bogus` makes `buildData` return `Pair.of("bogus", new MetaData())`. `"bogus"` is not a key in `decoratorMap` → `get` returns null → `.decorator(...)` NPEs inside `GlobalPlugin.execute` → 500 on the request thread. Also fires if a registered `MetaData.rpcType` has no matching decorator bean (plugin module absent).
-
Impact:
Single unauthenticated request with a bogus `rpc_type` header crashes `GlobalPlugin` with NPE (trivial DoS); misconfigured metadata crashes all requests of that rpc type.
-
Suggested fix:
Validate `rpcType` against `decoratorMap.containsKey(...)`; fall back to HTTP decorator or reject with 400. Treat the client `rpc_type` header as untrusted.
-
Confidence: High
- Related existing: FUNC-C4 (#6556) is websocket `Upgrade` case-sensitivity in the same method but a different branch; this is the missing null-guard on the decorator-map lookup.

---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/00-consolidated-critical-high.md`](docs/scan2-2026-08-02/00-consolidated-critical-high.md)._

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with shenyu-plugin/shenyu-plugin-global/src/main/java/org/apache/shenyu/plugin/global/DefaultShenyuContextBuilder.java, especially build() and the rpc_type header handling around lines 62 and 68. Reproduce the unknown-header case through GlobalPlugin.execute, then confirm the chosen fallback or rejection behavior prevents the decorator lookup from producing an NPE or a 500 response.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.