Skip to content

fix(yurthub): reject dot segments when building disk storage keys - #2848

Open
Sharadhi-v98 wants to merge 1 commit into
openyurtio:masterfrom
Sharadhi-v98:yurthub-disk-key-dot-segments
Open

Sharadhi-v98 wants to merge 1 commit into
openyurtio:masterfrom
Sharadhi-v98:yurthub-disk-key-dot-segments

Conversation

@Sharadhi-v98

Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it:

diskStorage.KeyFunc builds the on-disk cache key with filepath.Join(component, resource, namespace, name). The component is the client's User-Agent (cut at the first /), and resource, namespace and name come from the request path, which yurthub does not clean. Nothing rejected . or .., so a local client could move a key out of its component dir and, in two setups, out of --disk-cache-path:

  1. With cache_agents: "*", a request with User-Agent: .. is cacheable. Online, the response to GET /api/v1/namespaces/default/configmaps/foo is written to <cache-dir>/../configmaps.v1.core/default/foo. With the cloud unreachable, GET /api/v1/namespaces/../configmaps/<file> is served from <cache-dir>/../<file>, so any JSON object file next to the cache dir is returned to the client.
  2. With the older (non-enhancement) cache layout, the default kubelet agent is enough: GET /api/v1/namespaces/../../<file> while offline resolves to <cache-dir>/../<file>.

KeyFunc now returns storage.ErrUnrecognizedKey when the component, resource, namespace or name has a . or .. element. Create, Get, List, Update and ReplaceComponentList all build their keys here, so the one check covers them. Valid Kubernetes names and user agents never contain those elements, and a key error on the cache write path is only logged, so the proxied response is unchanged.

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

Does this PR introduce a user-facing change?

yurthub: reject "." and ".." in disk cache keys so requests can no longer read or write cache files outside --disk-cache-path.

KeyFunc joins the client component (from the User-Agent header) and the
resource, namespace and name (from the request path) into the on-disk
cache key. A "." or ".." in any of them moved the key out of its
component dir, and in some setups out of the cache dir, so yurthub could
write cached responses to, or serve files from, outside
--disk-cache-path.

Refuse "." and ".." elements in those fields and return
ErrUnrecognizedKey, the same error used for cluster info keys.
@Sharadhi-v98
Sharadhi-v98 requested a review from a team as a code owner November 6, 2026 17:58
@sonarqubecloud

sonarqubecloud Bot commented Nov 6, 2026

Copy link
Copy Markdown

@Sharadhi-v98

Copy link
Copy Markdown
Author

any update?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant