Skip to content
Path traversal Disclosed report Beginner CVE-2024-5182

LocalAI path traversal vulnerability

The model deletion endpoint in LocalAI 2.14.0 fails to validate the model parameter, allowing directory traversal. An attacker can delete arbitrary files outside the intended directory.

mudler/localai

Originally disclosed on huntr

A path traversal vulnerability exists in mudler/localai version 2.14.0, where an attacker can exploit the model parameter during the model deletion process to delete arbitrary files. Specifically, by crafting a request with a manipulated model parameter, an attacker can traverse the directory structure and target files outside of the intended directory, leading to the deletion of sensitive data. This vulnerability is due to insufficient input validation and sanitization of the model parameter.

From the GitHub Advisory Database (GHSA-cpcx-r2gq-x893, CC BY 4.0).

The original report as published on the GitHub Advisory Database. Images and videos are our own copies; raw HTML is shown as text. View it on GitHub Advisory Database.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 4 min read.

What the report shows

LocalAI is a project that serves models through an HTTP API, and version 2.14.0 exposes a model deletion feature. The report states that the model parameter is used during the model deletion process and can be manipulated to delete arbitrary files. The researcher found that the value of model is not validated or sanitised before it is used in that deletion, so a crafted request can walk out of the intended model directory and delete files elsewhere on the host.

The report describes the attack as crafting a request with a manipulated model parameter so that the directory structure is traversed and a file outside the intended directory is deleted. The report does not include the literal request, the endpoint path, the exact payload string, or a sample response, so there is nothing to reproduce verbatim here. It also does not name the researcher, give a CVSS score, or state a bounty amount.

The report was disclosed on 20 June 2024 and is mirrored from the GitHub Advisory Database under identifier GHSA-cpcx-r2gq-x893. The advisory text does not describe the patch commit or the fixed version, so the exact remediation is not documented in the material available.

Root cause

The report attributes the root cause to insufficient input validation and sanitisation of the model parameter. The model parameter is accepted from the request and used in the deletion process without sufficient validation or sanitisation. When user-controlled text reaches a filesystem call that way, .. segments and absolute paths can redirect the operation to any file the LocalAI process can write to.

Two separate failures usually combine here: input validation (rejecting or rewriting traversal sequences) and authorisation of the resulting path (confirming the canonical path is under the model root). The report attributes the issue to insufficient input validation and sanitisation of the model parameter.

Impact

An attacker can exploit the model parameter to delete arbitrary files. The report frames this as deletion of sensitive data. The report frames the impact as deletion of sensitive data. The report does not claim code execution, data disclosure, or privilege escalation, and none should be assumed from it. Whether an unauthenticated attacker can reach the endpoint is not stated.

How this kind of bug works

Path traversal happens when an application builds a filesystem path from user input and trusts the result. The operating system resolves .. segments and absolute paths at the point of the system call, so a value like a relative path with parent references, or a fully qualified path, can point anywhere the process has permissions. The danger is highest for write and delete operations, where the consequence is not just reading the wrong file but changing or destroying it.

Defences work at two levels. First, treat the parameter as an identifier rather than a path: look the model up in a table or map and use the stored path, never the submitted string. Second, if a path must be derived from input, canonicalise it (resolve symlinks and ..) and verify that the result is inside the expected base directory before acting. Rejecting strings that contain traversal sequences is a useful extra layer but is not sufficient on its own, because encodings, alternate separators and symlinks can bypass naive filters.

How to test for it

  1. Identify features that name a file or object supplied by the client: download, delete, rename, export, log viewing, template loading, model management.
  2. Map how the parameter is used. Send a benign value and observe behaviour; then send a value that resolves to a file you control or a harmless file you are authorised to touch.
  3. Try traversal sequences in the parameter, including encoded forms, doubled separators, and absolute paths. For destructive operations, test against a file you created for the purpose rather than a system file.
  4. Confirm the effect out of band: check whether the target file was actually read, moved or removed, rather than relying on an error message.

A positive result is a change to a file outside the intended directory that you can verify independently. Common false positives include error messages that merely echo the path, servers that normalise the path before use, and cases where the operation fails but the response looks successful. Also rule out caching and proxies that might mask the real behaviour.

How it is fixed

Standard fixes are to stop deriving filesystem paths from raw input, resolve and canonicalise any path that must be built, and enforce that the canonical result sits under the allowed base directory. Symlinks should be resolved before the check, and the check should happen as close as possible to the filesystem call to avoid time-of-check races. Where possible, restrict the service account's permissions so that even a successful traversal cannot reach sensitive files.

Hunting notes

This class tends to hide in administrative and file-management endpoints: model or plugin managers, backup and export features, log and report downloaders, theme and template loaders, and anything that accepts a filename. Recon signals include parameters named after files or objects, endpoints that return file contents or confirm deletions, and features that expose server-side storage to users. To make a report land, demonstrate a concrete, verifiable effect on a file outside the intended directory, keep the proof minimal and non-destructive where possible, and state clearly what the attacker needs to reach the feature. Avoid touching production data; use files you created for the test.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 6 min read.

What happened, in plain words

LocalAI is a piece of software that runs artificial intelligence models and lets other programs talk to them over the network. Version 2.14.0 of the project, published on GitHub as mudler/localai, includes a model deletion feature. The report says the model parameter is used during the model deletion process and can be manipulated to delete arbitrary files.

The problem is that the software does not check the value properly before using it. The report calls this "insufficient input validation and sanitisation of the model parameter". In everyday terms: imagine a cloakroom where you hand over a ticket with a number, and the attendant fetches whatever is written on it without checking that the number belongs to a coat in this cloakroom. If you write "the manager's coat" on the ticket, you get the manager's coat. Here, an attacker can write a value that points outside the folder where models are kept, and the software deletes that file instead.

The report describes the attack as crafting a request with a manipulated model parameter so that the directory structure is traversed and a file outside the intended directory is deleted. The report does not include the literal request, the endpoint path, the exact payload string, or a sample response, so there is nothing to copy verbatim here. It also does not name the researcher, give a CVSS score, or state a bounty amount.

It was disclosed on 20 June 2024 and is mirrored from the GitHub Advisory Database under identifier GHSA-cpcx-r2gq-x893. The advisory text does not describe the patch commit or the fixed version, so the exact fix is not documented in the material available.

Why this matters

Deleting a file is destructive and, without a backup, permanent. The report frames the impact as deletion of sensitive data. The report does not claim that an attacker can run code, read data, or gain higher privileges, and none of that should be assumed from it. Whether someone who is not logged in can reach the deletion feature is not stated.

The root cause

The report attributes the root cause to insufficient input validation and sanitisation of the model parameter. The model value arrives in the request and is used in the deletion process without sufficient validation or sanitisation. When text controlled by a user reaches a filesystem call that way, .. segments and absolute paths can redirect the operation to any file the LocalAI process is allowed to write to.

Two separate failures usually combine here: input validation (rejecting or rewriting traversal sequences) and authorisation of the resulting path (confirming the canonical path is under the model root). The report attributes the issue to insufficient input validation and sanitisation of the model parameter.

In general, how this kind of bug works

This class of bug is called path traversal. It happens when an application builds a filesystem path from user input and trusts the result. The operating system resolves .. segments and absolute paths at the point of the system call, so a value like a relative path with parent references, or a fully qualified path, can point anywhere the process has permissions. The danger is highest for write and delete operations, where the consequence is not just reading the wrong file but changing or destroying it.

Defences work at two levels. First, treat the parameter as an identifier rather than a path: look the model up in a table or map and use the stored path, never the submitted string. Second, if a path must be derived from input, canonicalise it (resolve symlinks and ..) and verify that the result is inside the expected base folder before acting. Rejecting strings that contain traversal sequences is a useful extra layer but is not sufficient on its own, because encodings, alternate separators and symlinks can bypass naive filters.

How to test for it

  1. Identify features that name a file or object supplied by the client: download, delete, rename, export, log viewing, template loading, model management.
  2. Map how the parameter is used. Send a benign value and observe behaviour; then send a value that resolves to a file you control or a harmless file you are authorised to touch.
  3. Try traversal sequences in the parameter, including encoded forms, doubled separators, and absolute paths. For destructive operations, test against a file you created for the purpose rather than a system file.
  4. Confirm the effect out of band: check whether the target file was actually read, moved or removed, rather than relying on an error message.

A positive result is a change to a file outside the intended folder that you can verify independently. Common false positives include error messages that merely echo the path, servers that normalise the path before use, and cases where the operation fails but the response looks successful. Also rule out caching and proxies that might mask the real behaviour.

How it is fixed

Standard fixes are to stop deriving filesystem paths from raw input, resolve and canonicalise any path that must be built, and enforce that the canonical result sits under the allowed base folder. Symlinks should be resolved before the check, and the check should happen as close as possible to the filesystem call to avoid time-of-check races. Where possible, restrict the service account's permissions so that even a successful traversal cannot reach sensitive files.

Hunting notes

This class tends to hide in administrative and file-management endpoints: model or plugin managers, backup and export features, log and report downloaders, theme and template loaders, and anything that accepts a filename. Recon signals include parameters named after files or objects, endpoints that return file contents or confirm deletions, and features that expose server-side storage to users. To make a report land, demonstrate a concrete, verifiable effect on a file outside the intended folder, keep the proof minimal and non-destructive where possible, and state clearly what the attacker needs to reach the feature. Avoid touching production data; use files you created for the test.

Glossary

  • LocalAI: software that runs AI models and serves them over a network API.
  • Model: a file or set of files that an AI system loads to work; here, the thing the deletion feature removes.
  • Parameter: a named value sent with a request, such as model, that the server reads and acts on.
  • Request: a message a browser or program sends to a server asking it to do something.
  • Endpoint: a specific address on a server that accepts a particular kind of request.
  • API: a defined way for programs to talk to each other, usually over HTTP.
  • HTTP: the protocol browsers and servers use to exchange requests and responses.
  • Path traversal: tricking software into using a file path that points outside the folder it intended, often with .. segments.
  • .. segment: a path component meaning "go up one folder".
  • Absolute path: a path that starts from the root of the filesystem rather than from the current folder.
  • Input validation: checking that data supplied by a user is acceptable before using it.
  • Sanitisation: cleaning or rewriting user input so that dangerous parts are removed.
  • Canonicalise: turn a path into its single, resolved form, following .. and symlinks.
  • Symlink: a shortcut file that points to another file or folder.
  • Filesystem call: an instruction to the operating system to read, write, move or delete a file.
  • Service account: the user identity a program runs under, which limits what files it can touch.
  • Denial of service: breaking a service so that it stops working for its users.
  • Privilege escalation: gaining more permissions than you were given.
  • CVSS: a scoring system that rates the severity of a vulnerability.
  • False positive: a test result that looks like a problem but is not one.
  • Time-of-check race: a gap between checking something and using it, during which it can change.
  • GitHub Advisory Database: a public collection of security advisories for open-source software.

More from mudler/localai

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.