[CLOSED] superseded by PR #369 (CWE-22 main-targeted) #345

Closed
fullstack-engineer wants to merge 1 commits from fix/security-CWE22-loadWorkspaceEnv-330 into staging

1 Commits

Author SHA1 Message Date
19b61729ac fix(security): CWE-22 path traversal guard in loadWorkspaceEnv
Some checks failed
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 10s
audit-force-merge / audit (pull_request) Has been skipped
sop-tier-check / tier-check (pull_request) Failing after 4s
OFFSEC-003 / closes #330.

`loadWorkspaceEnv` used `filepath.Join(orgBaseDir, filesDir, ".env")`
without a resolveInsideRoot guard on filesDir — allowing malicious org YAML
to read files outside the org root (e.g. filesDir: "../../../etc").

Two locations patched:

1. org_helpers.go:loadWorkspaceEnv — wrap filesDir with resolveInsideRoot
   before joining into the load path. On traversal rejection the org-root
   .env is still loaded; the traversal path is silently skipped.

2. org_import.go:createWorkspaceTree — same unguarded Join at line 494
   was patched with the identical guard.

resolveInsideRoot is already established in the codebase (used for
template and files_dir elsewhere in org_import.go), so no new primitives
are introduced.

Added org_helpers_test.go covering:
- Normal load of org-root + workspace .env (workspace overrides org)
- Traversal paths (../../../etc etc.) are silently rejected
- Non-existent workspace dir returns org-root vars only
- Empty orgBaseDir returns empty map
2026-05-10 23:12:21 +00:00