Is it safe to store application files to user’s temp directory?

I’m developing a Node.js library that collects data whenever user runs tests. I would like to persist the data on local disk so that after the test run, user can run a command accessing that data. The test data might potentially contain sensitive data depending on what the user is testing, such as API keys (if the user is accidentally using real API keys for testing).

My first idea was to save the files to temporary directory like this:

const tempBaseDirectory = path.join(os.tmpdir(), "my-directory");
const tempDirectory = fs.mkdtempSync(tempBaseDirectory + path.sep);

and write the files for the test run in tempDirectory. Then after the test run, I can look into tempBaseDirectory for all the files I need.

That works fine, but I’m a bit worried about security. Could other users access that data in some operating systems?

Would it be better to store the data in a folder in user home directory or in the app directory? The latter option would require the user to specifically git-ignore the files.

5

Direct answer

Is it safe to store application files to user’s temp directory?

To the letter of your question, yes, it is safe. However, very much take the bolded part into account. Not just any temp directory, only the user’s temp directory suffices because it is appropriately access controlled to only give access to the current user.

os.tmpdir() gives access to the OS’ temp directory and is therefore accessible by anyone who has access to this machine. Your temp files are not private to the user! Other users can access these files as well.

But what you can do is add encryption so that the data is unusable without the correct private key. This ensures that even when someone gains access to the file with ill intent (e.g. when the machine is compromised), that they can’t actually parse the data.


Caveat: admin access

Note that local admins will be able to access the files as well. This can be a compromise of the private information but this is a decision made on the OS level to allow local administrators full access to the machine. If that is unacceptable for the level of privacy you and your users are expecting, then you can’t really store anything on a machine.
But then again, technically speaking you wouldn’t even be able to store a multi-session bearer token on that machine either, as an admin could get access to that token if they really wanted to. In reality, users compromise their own security (e.g. storing passwords in their browser) without worrying about things like admin access.

So it’s up to you. If the privacy need is high (similar to banking information), don’t store anything sensitive (without encrypting it) if you want to guarantee full privacy protection for your user. If the privacy need is reasonable (not accessible by anyone except those with appropriate rights decided by whoever owns the machine), then a user’s folder is sufficiently private.

If you want to err on the safe side, encryption is a good way to ensure privacy from everyone including system admins, unless your files are prohibitively large to decrypt every time you want to access them.


User responsibility

@Kayaman deserves credit for posting it first, but I do want to add it as an answer rather than a comment.

Instead of fretting about the user’s privacy and how you should handle it, why not use some real life inversion of control and instead let the user choose for themselves where to store the files?

This means you no longer have to worry about it. The user can take the appropriate privacy steps that they feel is required.

You could still e.g. add a notice to the application UI that these files may contain sensitive data and urge the users to keep them safe, but the final decision lies with them and not with you.

I would like to persist the data on local disk so that after the test run, user can run a command accessing that data.

That’s reasonable and the User’s Temporary directory is as good a place as any to put it. Of course, it matters what they’re testing – if it’s a piece of server-side functionality, like a Web app, then it might be better to retain all of this information on the server and not have to write it to local disk at all.

Another big concern with the User’s Temporary directory is that Windows Disk Cleanup will blindly delete its contents when run and this is one of the first things that a Service Desk will suggest when the User starts to complain about running out of disk space!

The test data might potentially contain sensitive data depending on what the user is testing, such as API keys (if the user is accidentally using real API keys for testing).

That’s a worry, especially in the World of GDPR.

You’ll have to mitigate against this Risk; Getting rid of the data as soon as its no longer required is a good start.

I’m a bit worried about security. Could other users access that data in some operating systems?

Administrative users on that machine can access [just about] anything so yes, they would be able to see these files. if that’s a serious [enough] concern, consider encrypting the files on disk.

Would it be better to store the data in a folder in user home directory or in the app directory?

On Windows, Regular users cannot write into the app directory, so that’s probably a not a good choice.

Users can write into their own Home directory, but that’s also one of the places that they go for their files so adding these into there just opens them up for Users to “fiddle with”. That may or may not be an issue.

On Windows, subdirectories of %APPDATA% are a good choice. These are “local” to each User (although Admin-user accessible), writable by Regular Users but, most importantly, aren’t “on their radar” of places to look for “interesting” files. Also, this location can be replicated across machines, if you have this kind of “Roaming” setup.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật