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
2 changes: 1 addition & 1 deletion src/backend/src/api/APIError.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module.exports = class APIError {
message: 'Cannot copy an item to the root directory.',
},
'cannot_write_to_root': {
status: 422,
status: 403,
message: 'Cannot write an item to the root directory.',
},
'cannot_overwrite_a_directory': {
Expand Down
15 changes: 14 additions & 1 deletion src/puter-js/src/modules/FileSystem/operations/mkdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const mkdir = function (...args) {
}

return new Promise(async (resolve, reject) => {
// If auth token is not provided and we are in the web environment,
// If auth token is not provided and we are in the web environment,
// try to authenticate with Puter
if(!puter.authToken && puter.env === 'web'){
try{
Expand All @@ -44,6 +44,19 @@ const mkdir = function (...args) {

options.path = getAbsolutePathForApp(options.path);

// Check if trying to create directory in root (after resolving absolute path)
if (options.path === '/' || path.dirname(options.path) === '/') {
const errorResponse = {
status: 403,
message: "Cannot write an item to the root directory."
};
if (options.error) options.error(errorResponse);
reject(errorResponse);
return;
}



xhr.send(JSON.stringify({
parent: path.dirname(options.path),
path: path.basename(options.path),
Expand Down