================================================================================ legitbiz[research] // advisory ================================================================================ id: LB-2026-011 // session-file-store target: session-file-store <= 1.5.0 (npm) type: Path Traversal / Arbitrary File Write (CWE-22) severity: Critical (CVSS:3.1 9.8 - AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H) channel: GitHub Issues / Coordinated Disclosure date: 2026-11-27 status: submitted / vendor notified researcher: legitbiz[research] -------------------------------------------------------------------------------- [01] // summary -------------------------------------------------------------------------------- A path traversal vulnerability in session-file-store allows an attacker who controls the session ID to write session files to arbitrary locations on the server filesystem. The sessionPath() function joins user-controlled session IDs with the sessions directory without sanitizing '../' directory traversal sequences. -------------------------------------------------------------------------------- [02] // root cause analysis (lib/session-file-helpers.js) -------------------------------------------------------------------------------- session-file-store is an Express/Connect session store persisting sessions to individual JSON files on disk. The helper sessionPath() constructs paths with:  sessionPath: function (options, sessionId) {  return path.join(options.path, sessionId + options.fileExtension);  } Because sessionId originates directly from the client's session cookie, it is completely untrusted. When an attacker supplies a session cookie like `../../../tmp/pwned`, the set() function writes session data to:  path.join(options.path, '../../../tmp/pwned.json') which resolves outside the sessions directory. The same flaw affects get(), destroy(), and file deletion handlers. -------------------------------------------------------------------------------- [03] // proof of concept -------------------------------------------------------------------------------- const path = require('path'); function sessionPath(options, sessionId) {  return path.join(options.path, sessionId + options.fileExtension); } const options = { path: '/tmp/sessions', fileExtension: '.json' }; const traversal = sessionPath(options, '../../../tmp/pwned'); console.log('Resolved path:', path.resolve(traversal)); // Resolves to: /tmp/pwned.json (escapes /tmp/sessions/) // End-to-end: // 1. Attacker sends Cookie: connect.sid=s%3A..%2F..%2F..%2Ftmp%2Fpwned.sig // 2. sessionStore.set() writes session contents to /tmp/pwned.json -------------------------------------------------------------------------------- [04] // impact assessment -------------------------------------------------------------------------------- * CVSS v3.1 Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H (Score: 9.8 Critical) * Arbitrary file write and read on the server filesystem. An attacker can  overwrite critical application configuration files, plant payloads in  auto-executable directories, or overwrite user keys. -------------------------------------------------------------------------------- [05] // remediation -------------------------------------------------------------------------------- Sanitize the session ID before using it in path construction:  sessionPath: function (options, sessionId) {  if (sessionId.includes('..') || sessionId.includes('/') || sessionId.includes('\\')) {  throw new Error('Invalid session ID');  }  return path.join(options.path, sessionId + options.fileExtension);  } Alternatively, use path.basename(sessionId) or enforce strict alphanumeric regex. ================================================================================