Skip to content

fix(security): normalize MEMPALACE_PALACE_PATH env var with abspath+expanduser#1166

Merged
igorls merged 3 commits intoMemPalace:developfrom
arnoldwender:fix/security-palace-path-env-normalize
Apr 24, 2026
Merged

fix(security): normalize MEMPALACE_PALACE_PATH env var with abspath+expanduser#1166
igorls merged 3 commits intoMemPalace:developfrom
arnoldwender:fix/security-palace-path-env-normalize

Conversation

@arnoldwender
Copy link
Copy Markdown
Contributor

What and Why

MEMPALACE_PALACE_PATH (and legacy MEMPAL_PALACE_PATH) read from the environment was returned as-is from Config.palace_path, while the sibling --palace CLI path gets os.path.abspath() applied at mcp_server.py:62. The inconsistency lets env-var callers end up with a literal ~ or unresolved .. segments in the stored path, which breaks user intuition and lets a caller who can set env vars on the target user's session redirect palace storage somewhere the user didn't expect.

Root Cause

mempalace/config.py:167-172 — the env-var branch of the palace_path property short-circuits and returns env_val without running it through os.path.expanduser() / os.path.abspath().

Change Summary

  • mempalace/config.py — expand ~ and collapse .. on the env-var branch so both code paths converge on the same resolved absolute path. A 2-line inline comment notes the parity with the CLI code path.
  • tests/test_config.py — three new tests covering ~ expansion, .. collapse, and the legacy MEMPAL_PALACE_PATH alias getting the same treatment.

Test Plan

  • pytest tests/test_config.py -v — 25/25 pass (3 new tests green)
  • ruff check — clean
  • ruff format --check — formatted

Closes #1163

…xpanduser

MEMPALACE_PALACE_PATH (and legacy MEMPAL_PALACE_PATH) read from the
environment was returned as-is from Config.palace_path, while the
sibling --palace CLI path gets os.path.abspath() applied at
mcp_server.py:62. That inconsistency means env-var callers can end
up with literal '~' or unresolved '..' segments in the path, which
(a) breaks user intuition and (b) lets a caller who can set env vars
on the target user's session redirect palace storage to an
unexpected location.

Apply os.path.abspath(os.path.expanduser(...)) to the env-var branch
so both code paths converge on the same resolved absolute path.

Closes MemPalace#1163
The new abspath+expanduser normalization means /env/palace no longer
round-trips literally on Windows (abspath prepends the current drive,
producing D:\env\palace). Rewrite the env-var tests to compare against
os.path.abspath(os.path.expanduser(raw)) instead of hardcoded Unix
strings, and build raw paths with os.path.join so backslash-vs-slash
differences don't leak into assertions. Covers test_env_override, the
three new tests, and the legacy-alias test in test_config_extra.
Windows 8.3 short paths legitimately contain tildes (e.g. the CI runner's
USERPROFILE resolves to C:\Users\RUNNER~1\...), so asserting "~" is absent
from the expanded path fails on Windows even when expanduser worked
correctly. The equality check against os.path.abspath(os.path.expanduser())
is authoritative; drop the redundant absence heuristic.
@igorls igorls added bug Something isn't working security Security related labels Apr 24, 2026
@igorls igorls merged commit f246d25 into MemPalace:develop Apr 24, 2026
6 checks passed
jphein added a commit to jphein/mempalace that referenced this pull request Apr 24, 2026
… state

Three stale sections updated:

- Fork change queue: row 8 (.blob_seq_ids_migrated marker) struck
  through → FILED as MemPalace#1177. Two new rows added for segfault fixes
  discovered today (MemPalace#1171 concurrent-write lock, MemPalace#1173 quarantine in
  make_client) that weren't in the queue because the bugs surfaced
  today, not during the original 2026-04-21 triage.

- Open upstream PRs: was showing 3 of 10 PRs. Now shows all 10 with
  current CI/review state. All rebased onto current upstream/develop
  and MERGEABLE as of today.

- Merged since v3.3.1: added v3.3.3 release (2026-04-24) with its
  constituent merges — MemPalace#942, MemPalace#833, MemPalace#1097, MemPalace#1145, MemPalace#1147, MemPalace#1148/1150/1157
  entity-detection overhaul (via @igorls's MemPalace#1175 stacked-PR rescue),
  MemPalace#1166 palace-path security, MemPalace#340/MemPalace#1093 install regression, plus MemPalace#851
  from the 2026-04-22 batch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working security Security related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(security): normalize MEMPALACE_PALACE_PATH env var with abspath+expanduser

2 participants