
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
@ashnazg/dumbfile
Advanced tools
a barebones localfile-backed storage for stubbing out without redis or RDMS
a barebones localfile-backed storage for stubbing out without redis or RDMS
N.B. Don't put any cycles in your .db; this is just using JSON.stringify, so cycles will make it unsavable.
const jsonLoad = require('@ashnazg/dumbfile').load; // ~/projects/ashnazg-npm/dumbfile/json.js
var handle = await jsonLoad('./store.json');
console.log(handle.db); // contents of file are now ready on .db
handle.db.property = 'foo'; // mutate .db, it's just a plain old JS object.
await handle.save(); // saved back to disk, in a human-friendly format. Using tabs.
// admin edited config file while app was running?
await handle.reload(); // .db has been wiped and replaced with file's contents again.
var seven_days = 1000*60*60*24*7;
var session_db_ready = dumb.load('../tokens.json').then(sys => { // N.B. if you've got src/ watched with something like nodemon, make sure the state file isn't in the watch list.
// create schemas if missing
sys.db = Object.assign({
tokens: {},
}, sys.db);
sys.setSessionExpiration = function(user, lifespan = seven_days) {
var token = genToken(user, lifespan);
var expires_on = Date.now() + lifespan;
this.db.tokens[user] = this.db.tokens[user] || {}; // this could be the first token creation for this user
this.db.tokens[user][token] = expires_on;
this.save(); // firing and forgetting the 'save completed' promise; I don't need confirmation that this hit disk for just sessions.
console.log("new db", this.db);
return token;
};
sys.isValidSession = function(user, token) {
var my_tokens = this.db.tokens[user];
if (!my_tokens) return false;
var expiration_date = my_tokens[token];
if (expiration_date === undefined) return false;
if (expiration_date > Date.now()) return getUid(user);
delete my_tokens[token];
return false;
};
return sys;
}
// caller should provide exactly one of pass or token
async function checkAuth(user, pass, token) {
if (pass) {
var uid = checkPass(user, pass);
if (uid) {
var sys = await session_db_ready;
var token = sys.setSessionExpiration(user);
return {uid, token};
}
} else if (token) {
var sys = await session_db_ready;
uid = sys.isValidSession(user, token);
if (uid) {
return {uid, token};
}
throw {message: 'token expired'};
}
throw {message: 'no acceptable credential provided'};
}
There's a no-format-assumptions underlying layer you can use. It does speak only utf8, as I only use raw Buffers when I have to.
var loadFile = require('./utf8.js').createDumbFile;
var handle = loadFile('./store.raw');
var data = await handle.load();
await handle.save('new data');
It also has a synchronous save function:
handle.saveSync('new data');
Both of the handle creation functions have two more params: a default value that's returned when the file doesn't exist, and a chmod mode used during save()'s file creation.
var handle = loadFile(filename, 'default config lines', 0o660); // default chmod os owner r/w only; 660 says group also has r/w perms.
var handle = jsonLoad(filename, {default: 'setting'}, 0o660);
Turned off some dbg logging I didn't mean to commit
json file management no longer depends on {this.db} for anything -- this allows me to pass a subtree to a submodule, along with the save func, and now each submodule can share
dumb state file without knowing they're not the root.
Now treats empty files the same way it treats non-existent files: init the state to the specified defaults.
1.1.0 has a bug where multiple parallel calls to async save can result in the OS seeing overlapping writes during one "open for truncate and write" file handle.
So now, a horde of async save()s results in all but the first save leaving a note for the first save job to handle it, and then waiting for it to finally give the "latest version has been persisted."
FAQs
a barebones localfile-backed storage for stubbing out without redis or RDMS
We found that @ashnazg/dumbfile demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.