Readit News logoReadit News
gwbas1c · 4 years ago
At a minimum, this should be password protected by default.

One of the security lessons from the late 1990s and early 2000s is that things like this quickly get hacked. Many developers forget that a service where all security is handled client-side are easy targets for hacking.

Furthermore: In a lot of cases, people will ship prototypes and run their stuff on top of them long after they have outgrown a critical component.

I have tried to write a universal backend... It's possible, but you really have to work in a permissions model from the beginning. What you'll find is that basic read/write/own enables very basic functionality. Unfortunately, to do anything complicated, you will need to write server-side queries that verify that the user is allowed to do what they are trying to do.

btbuildem · 4 years ago
Pretty sure this is meant for prototyping and maybe demoing in controlled environments.

As soon as you involve auth, things get boring and annoying.

gwbas1c · 4 years ago
Honestly, anything simple. It could be as brain-dead simple as passing a password on the command-line, and then requiring the password as a header.
throw_m239339 · 4 years ago
> As soon as you involve auth, things get boring and annoying.

No, JWT is easy enough to implement.

aw4y · 4 years ago
A very basic REST service for JSON data - enough for prototyping and MVPs!

Features:

    no need to set up a database, all data is managed automagically*
    REST paradigm CRUD for multiple entities/namespaces
    schema validation
    search using jq like syntax 
    CORS enabled
    easy to deploy as container

torgard · 4 years ago
Just a heads-up, you might want to take down the example website. Now that it's been posted to HN you might see malicious actors.

I also think it's prone to SQL injection at the moment? At least, it's raising a syntax error when inputting an apostrophe.

grey-area · 4 years ago
Yes, don't do this:

https://github.com/rehacktive/caffeine/blob/master/database/...

"INSERT INTO %v (id, data) VALUES('%v','%v') ON CONFLICT (id) DO UPDATE SET data = '%v'"

Use prepared statements and parameters passed to the db driver, not building strings with strings or you are vulnerable to sqli.

I'd also avoid using %v anyway when building strings - safer to use a specific type like %d for int.

samstave · 4 years ago
>>Now that it's been posted to HN you might see malicious actors.

This needs to be an HN fN Masterclass by @Dang....

We should have regular visibility into /how/ HN is used by malicious actors.... HN has enough pedigree to get some insight from some of the top security folks... and it would be REALLY good to know how HN is being harvested in this space.

Dead Comment

sgt · 4 years ago
Feature request: supply .json file via command line to pre-load data into the in-memory database.

Taking it even further; how about persisting the data in the file?

Sometimes your prototype will need some pre-added data so I think this might be useful.

qw · 4 years ago
I have used WireMock in the past that supports pre-defined mocks. It can be run both locally and as a service (I only ran it locally)

http://wiremock.org/

It's more complex than Caffeine, but it has a lot of options.

It can also run as a proxy and generate the mocks from actual http requests passing through the proxy

aw4y · 4 years ago
currently there are two implementation for the database "behind": in memory or with postgres, both with zero config (except for starting an instance of postgres, in the second case!). it can be easily extended to use files as persistence, good idea :)

regarding the pre-population, you can just make a quick script with curl that will add some data after you run the service. any thought?

tbrock · 4 years ago
Thats code folks would have to write instead of focusing on the MVP, it would be better if this loaded it by convention.
nicoburns · 4 years ago
SQLite could also be a good option
skhm · 4 years ago
My first thought too, but I guess it's also very easy to hand-roll an init_data.sh script with a bunch of POST curls to populate the DB.
aw4y · 4 years ago
exactly!
lofties · 4 years ago
Can probably do that with some `jq` and CURL magic already!
thih9 · 4 years ago
FYI, there is a name clash with Caffeine, a Mac OS menu bar app that keeps the screen awake: https://intelliscapesolutions.com/apps/caffeine . But I guess this is expected with a name like this, and the scopes of the projects are clearly different, so this should be relatively harmless.
Danidada · 4 years ago
And also a (very efficient) Java cache library https://github.com/ben-manes/caffeine
lekevicius · 4 years ago
You don't need an app. `caffeinate` is a command line utility built into macOS.
jamesmishra · 4 years ago
Caffeine is also a central nervous system stimulant of the methylxanthine class.
cozzyd · 4 years ago
And a gnome shell extension that does the same thing.
das_keyboard · 4 years ago
Since we are collecting :) there is also a streaming service https://www.caffeine.tv/
brainzap · 4 years ago
A few requests should randomly fail to force the developer to think about handling errors. :)
codefined · 4 years ago
Hah! I'm not sure my MVP has ever had error handling beyond "Something went wrong.". That's something for a real production app, not the minimum possible product.

Deleted Comment

Method5440 · 4 years ago
You guys have errors in your programs? :)

Jokes aside… chaos engineering is a big deal right now - this isn’t a terrible idea and might be worthy of a fork.

jpdelatorre · 4 years ago
Another similar project that I use for mocking API server https://github.com/typicode/json-server
nkozyra · 4 years ago
I realize this is just for prototyping but it looks like it just spits sprintf SQL strings into the database.

While not a security risk if done locally, why not just use a where string builder to generate the $ values and a variadic as the input? It's about the same amount of work.

shireboy · 4 years ago
I could have used something similar recently, but that persisted to disk as json. I ended up just storing a wad of JSON on disk and memory, loading and saving as needed. Will only ever be 1M or so and only 2 users.