r/GoogleAppsScript • u/Being-Straight • Jan 09 '26
Resolved And Again, another reason why Sheets is not a DB (beware twin🥀)
So, a small cautionary tale for anyone (like me) who uses Google Sheets as a database via Google Apps Script.
As we all know, in GAS you basically have three ways to persist data:
- A real database via JDBC
- Cache / Properties / Script state (fine for small stuff, configs, flags, etc.)
- Google Sheets, a.k.a. “the thing everyone uses as a DB anyway”
Like many of you, I went with option #3. I even went a step further and built a whole library to treat Sheets like a real database: relational integrity, CRUD, references, junction tables, cascade deletes… the whole “poor man’s ORM” thing.
Why you say? Because at the time I had no budget and no permissions to spin up a real DB.Yes, I know. A tiny DB would’ve cost like $2/month. No, that was not an option. Corporate life.
Anyway, the library works. I use it. It’s not fast, not academically sound, not based on any paper… but it works. Fast-forward to this week, I’m building a small personal finance app for friends that went like this, WhatsApp to Lambda, lambda to GPT (to categorize transactions), GPT to my GAS project, then to the Sheet.
Before releasing it, I asked one of my best friends to do QA on it, to see if it wasn't straight slop. The guy is a mathematician, currently doing a doctorate, not a QA engineer, certainly not a dev (it infuriates him that git repos dont have a big ol' red "DOWNLOAD .EXE HERE!!" button). Very smart man
I show him the app and explain:
“You can create financial products accounts, funds, wallets and name them whatever you want. They’re not tied to banks, just labels.”
just when i thought he was putting 'Re-conquering Panama fund', bro says
“Wait… these names are stored in Google Sheets, right?”
Me:Yeah, through my library. Why?
bro:“What happens if I name one =1+1?”
At that exact moment, I knew i fucked up.
We submit the form, the request goes through the lib, record is saved, table refreshes, The fund's name is 2. (requisite mention of Bobby Tables -> https://xkcd.com/327/)
The fun part is that I had sanitized inputs against HTML / JS injection, no <script> tags, no XSS, I knew that one.
What I didn’t think about was formula injection. If you’re clever (or malicious), you can do things like:
=JOIN(",", A2:F100)
Congrats, you just turned your “fund name” into a CSV dump of the entire table.
So I immediately patched the library:
- Sanitized formula-leading characters (
=,+,-,@) - Added tests
- Updated the repo
Which is why I’m writing this post.
So
If you:
- Use Google Sheets as a database
- Expose it through Apps Script (web app / API)
- Accept user input
Sanitize for spreadsheet formulas!!!!
Sheets is Excel. Excel should not be a DB (but it is)
And Excel will execute your strings with zero hesitation.
If you’re using my library:
👉 Please update it, especially if your script is public-facing (just posted a release here or select version 7+ on the GAS editor).
Learn from my mistake so you don’t accidentally publish your entire “database” as a single cell
17
u/budz Jan 09 '26
:: laughs in MySQL ::
15
u/WillingnessOwn6446 Jan 09 '26
Dang. That's a good heads up. I appreciate it. What about just putting a ' in front of all the inputs? That would kill the formula.
15
u/zmandel Jan 09 '26
you don't need to sanitize or change the cell data. Just add a single quote at the beginning of the cell string. Sheets understands it and treats the string as-is. Its documented in sheets. when reading it back, it doesnt return it with the quote so its transparent to reads.
8
u/SecureWriting8589 Jan 09 '26 edited Jan 09 '26
Little Bobby Tables would love this.
Requisite XKCD link
4
u/ThePatagonican Jan 09 '26
I think you can add one more option to your list: consume the db via rest api, many tools out there support it with RLS like supabase, neon, etc. https://supabase.com/docs/guides/api . The free tiers are very generous.
2
u/Embarx Jan 09 '26
Just out of curiosity, what method are you using to retrieve data from the Google Sheet? Are you reading all the data at once (
getDataRange().getValues()) and parsing in code, or are you usingcreateTextFinder()to search for the specific value?2
u/wirefin Jan 09 '26
Great writing :) This also one of the insanely awesome things about Sheets as a DB. It's like a built-in headless spreadsheet calculation engine
2
u/brendenderp Jan 09 '26
I actually have a website that's decently popular and uses Google sheets for it's database 😅 no data is user facing and it means I can keep things going with $0 operations cost. Website averages about 800 visits per day and each visit logs to a tracker just with user agent and referral source. Nearly 100k entries and it's holding strong.
2
u/dimudesigns Jan 10 '26 edited Jan 10 '26
Using Google Sheets as a database...just the thought of it brings me literal pain. Does the organization you work for have a paid Google Workspace subscription? If so, AppSheet is an option; it comes bundled as a part of a paid Google Workspace subscription.
Better yet, try to get your higher ups to sign-off on a Google Cloud Run Function (its the Google equivalent of AWS Lambda - and far more powerful than GAS). It requires billing to be enabled on a GCP project but it doesn't require a paid subscription. Moreover, it comes with a very generous free tier so you're unlikely to be charged a cent for usage, as long as you stay under the monthly free quota.
Google Cloud offers managed database services via CloudSQL, Firestore, etc. but they don't come cheap. However, there are ways to leverage embedded databases, like SQLite or DuckDB from a Google Cloud Run Function, at little and in some cases no cost for relatively small datasets. Something to look into if you're curious.
2
u/Expensive_Act_1782 Jan 11 '26
I found JDBC extraction from our Google Cloud SQL database to be ridiculously slow. Lots of posts on StackExchange about poor performance (for example).
We switched to using the BigQuery Sheets data connector. It's very reliable and performs well on our application which is not huge but has a dozen or so tables of a few thousand rows and tens of columns that are easily replicated and updated to Sheets.
Our BigQuery usage pattern is:
This was a game changer for us in terms of how we use and share data. It's as performant as Excel + an ODBC connector, but I find Sheets a much better environment for group sharing than Excel.
2
u/digital_barf Feb 08 '26
I wonder if it's the same for appsheet using sheets as db, with or without appscript functions.
Thank you for making this post! This is a major security flaw I definitely need to check on.
2
u/automatemyweek Jan 12 '26
Great storytelling!
1
u/thelazyguy94 Jan 13 '26
How to learn apps script to make systems. I want to make an employee task management system and a bulk task assignment system.