Review request

School newsletter generator calls the API from the browser, is my key burned?

Solved · 13 views · asked by dana_ships · edited

Repo or live app

github.com/danawhitfield/newsletter-draft

Unsure about: SecurityCosts

Teachers paste notes and get a newsletter draft. ChatGPT gave me code that calls the API directly from the page with dangerouslyAllowBrowser: true, which I read as a suggestion rather than a warning. It has been live on the school domain for about six weeks. Usage looks normal so far.

Comment

2 answers

Marked as helpful by the asker
lena_ops · edited

Treat that key as public and rotate it today. Six weeks on a live domain means it is in browser history, in any proxy log along the way, and quite possibly in a scraper's database. Normal usage so far tells you nothing, because the cost of using someone else's key is zero and the finders are not in a hurry.

The fix is a server route in front of it. The key lives in an environment variable on the server, the browser posts the notes to /api/draft, the route calls the provider and streams the answer back. Same user experience, key never leaves your machine.

While you are writing that route, require a signed-in teacher and count calls per user per day in a table. A proxy without a limit is a public key with extra steps.

Comment
sven_fire · edited

Also set a hard monthly budget in the provider dashboard before you rotate, not after. The rotation window is exactly when you want a ceiling, and it takes a minute. Your own per-user counter protects you from your users, the dashboard cap protects you from everyone else.

Comment