fix(api/migrate): allow known framework source dirs, not just the librefang home#5614
Merged
Conversation
…refang home #5577 confined both migrate source_dir and target_dir to the librefang home (~/.librefang). But the documented migration sources — ~/.openclaw (and legacy .clawdbot/.moldbot/.moltbot), ~/.openfang, ~/.langchain, ~/.autogpt — are siblings of ~/.librefang, not descendants, so a real POST /api/migrate {source_dir: "~/.openclaw"} (and POST /api/migrate/scan) was rejected with "outside the allowed migration roots". The migrate-from-OpenClaw flow regressed. Add migrate_source_roots(): the source allow-list is the librefang home plus any known framework source dir that actually exists under the OS home (only existing dirs — validate_path_containment returns 500 on a root it cannot canonicalize). source_dir / scan use this list; target_dir keeps the librefang-home-only allow-list so writes never leave ~/.librefang. The #5577 containment guarantee (no ../symlink escape, no arbitrary-path oracle) is preserved — only the legitimate sibling source roots are added. Carries forward the source-dir half of the now-closed #5355.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem (regression from #5577)
#5577 hardened
POST /api/migrateandPOST /api/migrate/scanby confiningsource_dir/target_dirto an allow-list — but the allow-list was just thelibrefang home (
~/.librefang). The documented migration source dirs aresiblings of
~/.librefang, not descendants:~/.openclaw(legacy aliases~/.clawdbot,~/.moldbot,~/.moltbot)~/.openfang,~/.langchain,~/.autogptSo a real
POST /api/migrate {"source":"openclaw","source_dir":"~/.openclaw"}(and the sibling
/scan) is rejected with "outside the allowed migrationroots". The migrate-from-OpenClaw flow that
migrate_detectadvertises isbroken on
main.Fix
Add
migrate_source_roots(librefang_home, os_home):that actually exists under the OS home. Only existing dirs are added —
validate_path_containmentreturns 500 on a root it cannotcanonicalize, so a missing
~/.autogptmust never enter the list.migrate_scanandrun_migrate'ssource_diruse this list.run_migrate'starget_dirkeeps the librefang-home-only allow-list:reads may come from a source dir, but writes never leave
~/.librefang.The #5577 containment guarantees are preserved —
../symlink escapes and thearbitrary-path
.exists()oracle are still blocked; only the legitimate,existing sibling source roots are admitted, and only for reads.
Tests
crates/librefang-api/src/routes/config.rs→mod migrate_roots_tests:includes_only_existing_known_source_dirs— existing~/.openclaw/~/.langchainincluded; non-existent~/.autogpt/~/.openfangexcluded.no_os_home_yields_librefang_home_only—dirs::home_dir() == Nonefallsback to the librefang home only.
source_under_known_root_passes_but_target_stays_confined— reproduces theregression: a source under
~/.openclawis accepted; an off-list sibling isstill rejected; and
~/.openclawis rejected as a target root.Verification
cargo test -p librefang-api --lib migrate_roots— 3 passed (run in arust:latest container with
libdbus-1-dev, sincekeyring→dbus-secret-servicepulls libdbus on Linux; the host cargo shim lacks it).rustfmt --checkclean on the touched file.Relationship to #5355
Supersedes the source-dir half of the closed #5355 (which was itself
superseded by #5577 for the original audit). #5355's TOCTOU
post-creation re-canonicalize is not included here — it touches the
migration write path and is a separate hardening; flagged for a follow-up.