Skip to content

Commit 8c77ca1

Browse files
roomote[bot]roomotedaniel-lxs
authored
fix: exclude rules-{slug} folder from mode export paths (#6186)
Co-authored-by: Roo Code <[email protected]> Co-authored-by: Daniel Riccio <[email protected]>
1 parent 4a934f4 commit 8c77ca1

File tree

3 files changed

+459
-10
lines changed

3 files changed

+459
-10
lines changed

src/core/config/CustomModesManager.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -782,12 +782,11 @@ export class CustomModesManager {
782782
const filePath = path.join(modeRulesDir, entry.name)
783783
const content = await fs.readFile(filePath, "utf-8")
784784
if (content.trim()) {
785-
// Calculate relative path based on mode source
786-
const relativePath = isGlobalMode
787-
? path.relative(baseDir, filePath)
788-
: path.relative(path.join(baseDir, ".roo"), filePath)
785+
// Calculate relative path from within the rules directory
786+
// This excludes the rules-{slug} folder from the path
787+
const relativePath = path.relative(modeRulesDir, filePath)
789788
// Normalize path to use forward slashes for cross-platform compatibility
790-
const normalizedRelativePath = relativePath.toPosix()
789+
const normalizedRelativePath = relativePath.replace(/\\/g, '/')
791790
rulesFiles.push({ relativePath: normalizedRelativePath, content: content.trim() })
792791
}
793792
}
@@ -883,11 +882,21 @@ export class CustomModesManager {
883882
continue // Skip this file but continue with others
884883
}
885884

886-
const targetPath = path.join(baseDir, normalizedRelativePath)
885+
// Check if path starts with a rules-* folder (old export format)
886+
let cleanedRelativePath = normalizedRelativePath
887+
const rulesMatch = normalizedRelativePath.match(/^rules-[^\/\\]+[\/\\]/)
888+
if (rulesMatch) {
889+
// Strip the entire rules-* folder reference for backwards compatibility
890+
cleanedRelativePath = normalizedRelativePath.substring(rulesMatch[0].length)
891+
logger.info(`Detected old export format, stripping ${rulesMatch[0]} from path`)
892+
}
893+
894+
// Use the rules folder path instead of base directory
895+
const targetPath = path.join(rulesFolderPath, cleanedRelativePath)
887896
const normalizedTargetPath = path.normalize(targetPath)
888-
const expectedBasePath = path.normalize(baseDir)
897+
const expectedBasePath = path.normalize(rulesFolderPath)
889898

890-
// Ensure the resolved path stays within the base directory
899+
// Ensure the resolved path stays within the rules folder
891900
if (!normalizedTargetPath.startsWith(expectedBasePath)) {
892901
logger.error(`Path traversal attempt detected: ${ruleFile.relativePath}`)
893902
continue // Skip this file but continue with others

0 commit comments

Comments
 (0)