1743164959

Write application settings and logs to a user-accessible folder


Too many applications still write logs and preferences into the application folder. That breaks the application and opens the door to security problems. In many cases, that folder doesn't allow the user to change anything. No write access allowed. So instead, you need to make sure your application saves the user's settings and your application's log files in a folder that does let the user write to it. Sometimes that is the application folder - that depends on the operating system and the type of application. But if your application is installed on a Microsoft Windows computer, in the default Program Files directory, the user has no write access. Instead, you need to write to the user-specific Local folder in the user's AppData folder. And if your application is installed on an Apple computer running MacOS, you need to write to the user-specific Application Support folder. There is no technical limitation here. Every major programming language has hooks to the API of the target operating system. Those allow any software engineer to ask the system: where can the user write? What is the problem with writing to the application folder, where the user normally doesn't have write access? Doing so means that the computer administrator has to allow the user to write into the application folder. Either the user has to run as an administrator (which is a huge red flag for security). or the administrator has to change the access settings to the default program installation folder in the operating system (which is another huge red flag). Both options leave the computer vulnerable to attack by malware. Do better.

(2) Comments
fschmidt
fschmidt
1744820763

Can you be specific? If I am writing an app called "app-name" on a Mac, then config should go in ~/.app-name ? Where should logs go?

aev_software
aev_software
1744834376

For MacOs the preferences should go into ~/Library/Preferences/. Name the file using RDN (reverse domain name notation) like so: org.mycharity.myapp, and store it in PList format.


Welcome to Chat-to.dev, a space for both novice and experienced programmers to chat about programming and share code in their posts.

About | Privacy | Donate
[2025 © Chat-to.dev]