Skip to content
Medium 4.4

Path traversal via stored raw docpath allows a manager to write/read files outside storage/documents

GHSA-3f4c-xj8r-h4cr First seen on SecPulse

Summary

Summary

AnythingLLM validates a document path at ingest using a normalized copy of the input, but
persists the original (un-normalized) string as the document's docpath. Background jobs and
document helpers later re-resolve that stored raw docpath against storage/documents **withou...

Original description The description as published by the source.

Summary

AnythingLLM validates a document path at ingest using a normalized copy of the input, but
persists the original (un-normalized) string as the document's docpath. Background jobs and
document helpers later re-resolve that stored raw docpath against storage/documents without
any containment (isWithin) check
. As a result, a user with the manager (or admin) role can
cause the server to write a document-JSON file to a chosen path outside storage/documents,
overwriting existing writable files on the host, and can cause reads outside the directory as well.

Details (root cause)

Verified against source at commit 65f83f3e47192843ded1228acdff86b00106c0cc (v1.16.1-era master):

  1. server/models/documents.js addDocuments() validates via fileData(path) (which normalizes
    and enforces isWithin) at line 109, but then stores the raw path into docpath at
    line 124 (docpath: path). The native embedder worker
    server/jobs/embedding-worker.js:94 stores the raw filePath the same way.
  2. server/jobs/sync-watched-documents.js:149 passes the stored raw document.docpath into
    updateSourceDocument(...).
  3. server/jobs/helpers/index.js updateSourceDocument() does
    path.resolve(documentsPath, docPath) (line 24) and fs.writeFileSync(...) (line 25)
    with no isWithin check (function body lines 23–28).
  4. The read sink server/utils/DocumentManager/index.js:38
    (`path.resolve(this.documentSto…

Source: GitHub Repository Security Advisories (Game のスタック) GitHub Advisory OSV

References

We use cookies for analytics and ad measurement. This setting applies to all Game co., Ltd. sites. Details