Skip to content

Security Vulnerability in Apps Script API #156

Open
@AQIB-NAWAB

Description

@AQIB-NAWAB

Right now, anyone who knows the API URL can send a request and add data to our Google Sheet. This means unauthorized users could add fake or incorrect data just by making a POST request.

Why is this happening?

The API doesn’t have any security checks in place. There’s nothing stopping someone from sending data, even if they’re not supposed to.

Solution

  1. We should require a SECRET_KEY with every request. Here’s how it will work:
  2. The frontend will send a SECRET_KEY along with the request in body.
  3. The Apps Script function will check if the key matches the one stored on the backend.
  4. If the key is correct, the request is processed. If not, it gets rejected immediately.

Here is the code to solve the problem

const SECRET_KEY = "OUR_SECRET_KEY";
const postData = JSON.parse(e.postData.contents);
const receivedSecret = postData.secret_key;

// Check if the secret key is provided and matches
    if (!receivedSecret || receivedSecret !== SECRET_KEY) {
      return ContentService.createTextOutput(
        JSON.stringify({ status: "error", message: "Unauthorized access" })
      ).setMimeType(ContentService.MimeType.JSON);
    }

Here is the video of current behavior

Screencast.from.2025-03-22.19-41-24.webm

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: TriageThis is the initial status for an issue that requires triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions