Skip to content
Open
Changes from 1 commit
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 packages/server/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ export const getEncryptionKey = async (): Promise<string> => {
const defaultLocation = process.env.SECRETKEY_PATH
? path.join(process.env.SECRETKEY_PATH, 'encryption.key')
: path.join(getUserHome(), '.flowise', 'encryption.key')
await fs.promises.writeFile(defaultLocation, encryptKey)
await fs.promises.writeFile(defaultLocation, encryptKey, { mode: 0o600 })
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

While adding { mode: 0o600 } is a good security practice, there are two additional improvements for robustness and complete hardening:

  1. Directory Creation: fs.promises.writeFile will throw an error if the parent directory (e.g., ~/.flowise) does not exist. This is likely to happen on fresh installations. Using fs.promises.mkdir with { recursive: true } ensures the directory exists before writing.
  2. Existing Files: The mode option in writeFile only applies when a new file is created. If the file already exists (e.g., if it was corrupted or empty, causing the initial readFile to fail), its permissions will not be updated. Adding an explicit fs.promises.chmod call ensures the file is hardened regardless of whether it was created or overwritten.

Additionally, consider applying similar hardening to other sensitive files, such as those handled in getOrCreateStoredSecret (line 1735).

        await fs.promises.mkdir(path.dirname(defaultLocation), { recursive: true })
        await fs.promises.writeFile(defaultLocation, encryptKey, { mode: 0o600 })
        await fs.promises.chmod(defaultLocation, 0o600)

return encryptKey
}
}
Expand Down