Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions src/commands/functions/functions-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ const downloadFromURL = async function (command, options, argumentName, function
folderContents.map(async ({ download_url: downloadUrl, name }) => {
try {
const res = await fetch(downloadUrl)
const finalName = path.basename(name, '.js') === functionName ? `${nameToUse}.js` : name
const finalName = path.basename(name, '.js') === functionName
? `${nameToUse}.js`
: path.basename(name) // ← strip any directory components
const dest = fs.createWriteStream(path.join(fnFolder, finalName))
res.body?.pipe(dest)
} catch (error_) {
Expand Down Expand Up @@ -744,14 +746,20 @@ const registerEFInToml = async (funcName, options) => {
* @returns
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'functionsDir' implicitly has an 'any' t... Remove this comment to see the full error message
const ensureFunctionPathIsOk = function (functionsDir, name) {
const functionPath = path.join(functionsDir, name)
if (fs.existsSync(functionPath)) {
log(`${NETLIFYDEVLOG} Function ${functionPath} already exists, cancelling...`)
process.exit(1)
const ensureFunctionPathIsOk = function (functionsDir, name) {
// Prevent path traversal: reject names like "../../evil"
const resolvedFunctionsDir = path.resolve(functionsDir)
const functionPath = path.join(resolvedFunctionsDir, name)
if (!functionPath.startsWith(resolvedFunctionsDir + path.sep)) {
log(`${NETLIFYDEVERR} Invalid function name: "${name}" resolves outside the functions directory.`)
process.exit(1)
}
if (fs.existsSync(functionPath)) {
log(`${NETLIFYDEVLOG} Function ${functionPath} already exists, cancelling...`)
process.exit(1)
}
return functionPath
}
Comment thread
NiteshCodes7 marked this conversation as resolved.
return functionPath
}

// Scans `functions-templates/<lang>` for a template whose `.mjs` metadata
// `name` matches. Returns its `functionType` and the language folder it lives
Expand Down