Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secure temp dir in NodeJS without dependencies #81

Open
jimmywarting opened this issue Jun 13, 2021 · 0 comments
Open

Secure temp dir in NodeJS without dependencies #81

jimmywarting opened this issue Jun 13, 2021 · 0 comments

Comments

@jimmywarting
Copy link

I'm looking into ways to reduce the footprint from all dependencies to try and reduce the overall size.
One of them i looked into was if unique-string was really needed.

configstore/index.js

Lines 7 to 9 in 02f07ea

import uniqueString from 'unique-string';
const configDirectory = xdgConfig || path.join(os.tmpdir(), uniqueString());

After reading up on some natives way of solving this problem i found this nice article that solves it in a very straight forward way:
https://advancedweb.hu/secure-tempfiles-in-nodejs-without-dependencies/

mkdtemp handles randomness and uniqueness without collision

import fs from 'fs'
import os from 'os'
import path from 'path'
// import uniqueString from 'unique-string';

// const configDirectory = xdgConfig || path.join(os.tmpdir(), uniqueString()); 
const configDirectory = xdgConfig || fs.mkdtempSync(fs.realpathSync(os.tmpdir()) + path.sep);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant