MCPcopy Create free account
hub / github.com/vercel/vercel / getUnsafePackageDirectoryReason

Function getUnsafePackageDirectoryReason

packages/cli-exec/src/safety.ts:105–127  ·  view source on GitHub ↗
(
  nodeModulesDirectory: string,
  packageDirectory: string
)

Source from the content-addressed store, hash-verified

103 * Validates that each package directory segment is safe and under node_modules.
104 */
105export async function getUnsafePackageDirectoryReason(
106 nodeModulesDirectory: string,
107 packageDirectory: string
108): Promise<string | null> {
109 const directoriesToCheck = getDirectoriesBetween(
110 nodeModulesDirectory,
111 packageDirectory
112 );
113
114 if (directoriesToCheck.length === 0) {
115 return `${packageDirectory} resolves outside local node_modules`;
116 }
117
118 for (const directory of directoriesToCheck) {
119 const reason = await getUnsafeDirectoryReason(directory);
120
121 if (reason) {
122 return `${directory} is ${reason}`;
123 }
124 }
125
126 return null;
127}
128
129/**
130 * Validates that package file ancestors and the file itself are safe.

Callers 2

getLocalVercelPackageFunction · 0.90

Calls 2

getDirectoriesBetweenFunction · 0.90
getUnsafeDirectoryReasonFunction · 0.85

Tested by

no test coverage detected