Security Design for Safe Operations

Defense-in-depth security architecture that small businesses can trust

SecurityToken AuthenticationRate LimitingCredential ManagementAccess Control
4 min read

About This Topic

In business systems, security is paramount.
Unauthorized access or data leaks can damage a company's reputation.

This project adopted a defense-in-depth security design so small businesses can use it with confidence.

Defense in Depth

Relying on a single defense measure is risky.
With multiple layers, even if one is breached, the next layer still provides protection.

In practice, this layered mindset is what keeps operations stable.

Four-Layer Security Structure
Layer 1: Token Authentication

Verify legitimate access with secret token

Pass
Layer 2: Rate Limiting

Block mass requests in short timeframes

Pass
Layer 3: Input Validation

Reject invalid data before processing

Pass
Layer 4: Secure Credential Management

Encrypted storage + auto-renewal

Layer 1: Token Authentication

Communication from GAS uses a secret token of 32+ characters.
Access from third parties who don't know this token is automatically rejected.

Token Management Tips

Layer 2: Rate Limiting

A mechanism that automatically blocks a flood of requests in a short time.
It helps with both malicious traffic and accidental overuse.

Rate Limiting Operation
Request Received

Identify by client IP + last 8 characters of token

Check Count

Check request count in the past minute

Under 60
Allow and increment count
60 or more
Return 429 Too Many Requests

What Rate Limiting Prevents

  • Malicious mass access: Denial of service attacks
  • Operational errors: Duplicate processing from button mashing
  • Infinite loops: Endless requests from program bugs

Response Header Notifications

API responses include the remaining request count.

Layer 3: Input Validation

Strictly check if submitted data is in the correct format before processing.

When Validation Finds Issues

Returns an error before processing begins, preventing invalid data from being sent to the invoicing service.

Layer 4: Secure Credential Management

Credentials (access tokens) needed to connect to the invoicing service require special handling.

Three Credential Management Techniques

Token Auto-Renewal Flow
Token Retrieval Request

Get token before API call

Check Expiry

More than 60 seconds remaining?

Valid
Use cached token
Near expiry
Acquire distributed lock and refresh
API Call

Make request with valid token

How Distributed Locking Works

If multiple requests try to refresh the token simultaneously:

  • Same token refreshed multiple times (wasted API calls)
  • Old and new tokens mixed (inconsistency)

Distributed locking ensures only one instance can refresh the token at a time.

Security Design Summary

What This Design Achieves

For Operations

  • Reduced security workload: Automated protection mechanisms
  • Easy incident response: Just change the token
  • Audit compliance: Track history with structured logs

For Users

  • Safe to use: Protected by defense in depth
  • Transparency: Know remaining rate limit
  • Quick error notification: Immediate awareness of issues