MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / isPathAllowed

Function isPathAllowed

src/utils/permissions/pathValidation.ts:145–272  ·  view source on GitHub ↗
(
  resolvedPath: string,
  context: ToolPermissionContext,
  operationType: FileOperationType,
  precomputedPathsToCheck?: readonly string[],
)

Source from the content-addressed store, hash-verified

143 * resolution is still required for those.
144 */
145export function isPathAllowed(
146 resolvedPath: string,
147 context: ToolPermissionContext,
148 operationType: FileOperationType,
149 precomputedPathsToCheck?: readonly string[],
150): PathCheckResult {
151 // Determine which permission type to check based on operation
152 const permissionType = operationType === 'read' ? 'read' : 'edit'
153
154 // 1. Check deny rules first (they take precedence)
155 const denyRule = matchingRuleForInput(
156 resolvedPath,
157 context,
158 permissionType,
159 'deny',
160 )
161 if (denyRule !== null) {
162 return {
163 allowed: false,
164 decisionReason: { type: 'rule', rule: denyRule },
165 }
166 }
167
168 // 2. For write/create operations, check internal editable paths (plan files, scratchpad, agent memory, job dirs)
169 // This MUST come before checkPathSafetyForAutoEdit since .claude is a dangerous directory
170 // and internal editable paths live under ~/.claude/ — matching the ordering in
171 // checkWritePermissionForTool (filesystem.ts step 1.5)
172 if (operationType !== 'read') {
173 const internalEditResult = checkEditableInternalPath(resolvedPath, {})
174 if (internalEditResult.behavior === 'allow') {
175 return {
176 allowed: true,
177 decisionReason: internalEditResult.decisionReason,
178 }
179 }
180 }
181
182 // 2.5. For write/create operations, check comprehensive safety validations
183 // This MUST come before checking working directory to prevent bypass via acceptEdits mode
184 // Checks: Windows patterns, Claude config files, dangerous files (on original + symlink paths)
185 if (operationType !== 'read') {
186 const safetyCheck = checkPathSafetyForAutoEdit(
187 resolvedPath,
188 precomputedPathsToCheck,
189 )
190 if (!safetyCheck.safe) {
191 const failedCheck = safetyCheck as {
192 safe: false
193 message: string
194 classifierApprovable: boolean
195 }
196 return {
197 allowed: false,
198 decisionReason: {
199 type: 'safetyCheck',
200 reason: failedCheck.message,
201 classifierApprovable: failedCheck.classifierApprovable,
202 },

Callers 2

validateGlobPatternFunction · 0.70
validatePathFunction · 0.70

Calls 6

matchingRuleForInputFunction · 0.85
pathInAllowedWorkingPathFunction · 0.85

Tested by

no test coverage detected