Glob injection is an input-handling vulnerability where user-controlled text is interpreted as a glob pattern, which is a wildcard-based file matching expression. When an application passes that pattern to file search or shell logic without validation, an attacker can match unexpected files or alter file selection.
What Glob Injection Actually Changes
Glob injection turns a seemingly simple filename or path lookup into an attacker-controlled pattern-matching problem. The danger is not just that the application reads the wrong file, but that wildcard expansion can widen the search set, exclude intended files, or make downstream logic operate on results the developer never meant to accept.
Because glob syntax is expressive, the same input can behave differently across shells, libraries, and operating systems. That makes it easy to miss during review: code that looks like a harmless search helper may actually be interpreting user input as a selector language.
How Glob Patterns Become a Security Boundary
A glob is designed for matching file names with wildcards such as * and ?. That is useful when the application controls the pattern. It becomes risky when the user controls the pattern, because the program is no longer asking, “which file did the user mean?” It is asking, “which files satisfy this expression?”
This shifts the trust boundary from the application to the input. In file discovery, import routines, cleanup jobs, archive handling, and shell-backed workflows, a glob may determine what is opened, copied, deleted, or processed next. If the pattern is not tightly constrained, the attacker can influence selection logic rather than just data content.
For general application risk context, the OWASP Top 10 remains a useful baseline for input-handling flaws and unsafe trust in user-supplied values.
Common Failure Modes and Exposure Paths
Glob injection usually appears where developers reuse a search or expansion helper instead of treating input as a literal string. The failure is often an assumption mismatch: a parameter intended to name one file is handled as a pattern that can match many files. That can lead to unintended disclosure, broad matching, or destructive actions against a larger set of files than intended.
The risk increases when globbing is combined with shell commands, recursive file traversal, backup scripts, log rotation, or batch processing. In those cases, a pattern can affect both what the application sees and what follow-on logic does with the matched set. Even when the result is “only” an unexpected file list, that can still expose sensitive paths, secrets, or operational data.
Safe Handling of User-Supplied File Selection
Defensive design starts by separating literal input from pattern input. If the user is meant to specify a single file, the application should treat the value as a literal path, not as a glob. If pattern matching is genuinely required, restrict the allowed syntax, scope the directory, and make the match set observable before any sensitive operation runs.
Prefer explicit allowlists, fixed base directories, and APIs that avoid shell interpretation altogether. When file selection must be dynamic, validate the expression before expansion and fail closed if it contains metacharacters outside the intended model. That keeps the pattern language from becoming an accidental control plane.
Detection and Review Considerations
Look for code paths where user input reaches file enumeration, shell invocation, or recursive selection without escaping or validation. Reviewers should pay particular attention to helper functions that look benign but pass through to the operating system, because glob injection is often hidden in ordinary-looking “find,” “match,” or “cleanup” logic.
Operationally, the most useful clue is unexpected breadth in file matches or repeated attempts to supply wildcard characters where a literal filename should be accepted. If a post-change review shows that a pattern was expanded before authorization or before a safety check, the logic deserves the same scrutiny as any other input-handling flaw.
Risk and Threat Considerations
Glob injection matters because it lets an attacker steer file selection without needing to break authentication or bypass a classical permission check. If the application expands patterns against a sensitive directory, the result can be unintended file disclosure, destructive over-selection, or a broader set of inputs being fed into later processing stages.
Failure mechanism: User-controlled glob metacharacters alter the match set, so the application processes files the developer did not intend to expose or act on. When that match set is later used for reading, deleting, importing, or archiving, the impact can extend beyond a single filename into a larger trust and data-handling failure.
Impact: The practical consequence is often unauthorized file discovery, accidental overwriting or deletion, or leakage of sensitive local paths and content. In workflows that feed matched files into automation, the attacker may also influence downstream behavior by changing which inputs exist at all.
Practitioner Guidance
Why practitioners should care: Glob injection is easy to underestimate because it looks like a parsing problem, but it is really an input trust problem. Any code that turns user text into a search expression should be reviewed as a security boundary, not just a convenience feature.
Common misunderstanding: Developers often assume that quoting or basic sanitisation is enough. That is not true when the application still interprets wildcard syntax, because the issue is semantic control over matching, not only character escaping.
Practitioner takeaway: If the user is not supposed to choose a set of files, do not let them provide a pattern. Treat file names as literals by default, and only enable glob semantics where the business requirement explicitly demands it.
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 16, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org