·7 min read
ByDaniel A·Kraftwire Software

Open API Security: How to Protect Your AI App's Public Endpoints

Illustration for Open API Security: How to Protect Your AI App's Public Endpoints

Public API security concerns the endpoints an application exposes, including routes that call an AI provider. Review who can invoke each operation, which data it can access, and how much usage it permits. Inspect frontend bundles for exposed secret keys and test authorization on backend routes.

Protecting an API requires more than keeping a key hidden. Validate request structure, enforce the caller's permissions, set usage limits, and keep long-lived secret provider credentials out of the client browser.

These live figures describe all scanned sites. They do not establish prevalence for an AI-built subgroup, compare development methods, or attribute findings to AI generation.

30% of the 125 live sites SimplyScan has scanned (37 sites) have at least one medium-severity web-security issue, such as a missing Content-Security-Policy or HSTS header.

What Does Public API Security Cover?

This guide covers your app's publicly reachable endpoints and its connections to external AI services. A public endpoint can still require authentication and authorization. This is separate from OpenAPI, the specification format used to describe HTTP APIs.

Choose an AI provider and model based on your application's requirements, and check its current documentation for supported authentication and access controls.

For OpenAI, follow the API authentication guidance: keep secret API keys in server-side environment variables or a key management service.

A leaked key can allow unauthorized requests and spending within its permissions. The data an attacker can access depends on the credential's scope and the provider's APIs; a key leak does not automatically expose every user prompt.

The Role of MCP in API Connectivity

MCP connects compatible AI clients with tools and data sources. Review each server's permissions, the credentials it receives, and the operations it exposes. A tool that can read private data or change records needs authorization at the point of access, regardless of whether the request comes from an AI agent.

Which API Risks Should AI App Developers Review?

Generated code needs the same review of trust boundaries as other code. A reference such as process.env.OPENAI_API_KEY is not proof that a value stays on the server: inspect how the framework builds and executes that code, and whether the credential reaches the client.

31% of the 125 live sites SimplyScan has scanned (39 sites) have at least one high or critical security issue.

Separate risks to review include:

  • Exposed API keys in JavaScript bundles.
  • Browser-origin permissions that do not match the API's intended use.
  • Missing input validation or authorization on backend routes.
  • Publicly accessible .env files.

Review environment variable handling in source files, build output, deployment settings, and logs. The variable's name alone does not determine whether its value becomes public.

How Can You Prevent API Key Leaks in Frontend Code?

Keep secret keys out of browser-delivered files and inspect the deployed bundle for exposure. Frameworks such as Next.js and Vite use NEXT_PUBLIC_ and VITE_ prefixes for values that may be exposed to client code when referenced. Do not place secrets in those client-facing variables.

For calls that need a secret provider key, use a server-side endpoint such as /api/chat. The backend attaches the credential and calls the provider. Authenticate and authorize the caller where required, validate the operation, and enforce usage limits; otherwise the endpoint can become an open proxy even while the key remains hidden.

Steps to Secure Your Keys

  1. Store secret keys in server-side secret configuration. If using a local .env file, exclude it from version control and public serving.
  2. Check reachable deployed files with the secret scanner. Review the repository and relevant history separately; URL scans do not read private Git history.
  3. Revoke exposed credentials, create replacements, and investigate usage. Removing a key from code does not revoke it.
  4. For credentials issued by your own service, an API key generator can generate a random value. Your service still needs secure storage, verification, permissions, and revocation.

What Are API Security Best Practices for Vibe-Coded Apps?

Use a vibe-coding security checklist to review generated changes before deployment. Test the actual headers, routes, and database permissions rather than relying on assumptions about a builder's defaults.

Implement Rate Limiting

Repeated AI requests can consume provider usage and backend resources. Limit request rates, input and output sizes, concurrency, and per-user usage as appropriate. Review provider spending controls separately; one rate limit does not guarantee a cost ceiling.

Validate and Sanitize Inputs

Prompt injection can occur when untrusted instructions influence a model's behavior. Validate request structure and size, but do not treat JSON validation or a guardrail model as proof that a prompt is safe. Keep secrets out of model context, limit tool permissions, validate outputs before acting on them, and require authorization for sensitive operations outside the model.

Use Proper Security Headers

Review browser protections for the responses your app serves. SimplyScan can inspect supported security-header signals in responses it reaches. Configure policies for your application and test their effects:

  • Content-Security-Policy (CSP) restricts browser behavior according to the directives you configure; it is not complete XSS protection.
  • X-Content-Type-Options: nosniff limits MIME sniffing in the browser contexts where it applies.
  • Strict-Transport-Security (HSTS) tells supporting browsers to use HTTPS after learning the policy; first-visit protection requires additional consideration.

Use the CSP generator to draft a policy, then test it against the resources your frontend needs. If provider requests run on your backend, browser CSP does not control those server-to-server requests.

Is Your Database API Secure?

Supabase/Postgres can use RLS to enforce row-level policies for roles subject to it. With RLS disabled, access depends on table privileges; it is not automatically public. Firebase uses its own Security Rules rather than Postgres RLS. Test the controls for the backend you actually use.

The live architecture figures below describe the scanner's architecture category across sites; they do not measure the prevalence of missing RLS. See architecture risks for related review topics.

10% of the 125 live sites SimplyScan has scanned (13 sites) have at least one medium-severity architecture issue, such as a library with a known vulnerability or no rate limiting.

Test RLS policies with signed-out users, owners, other users, and privileged roles as applicable. Define the access your app intends, including any legitimate sharing, rather than assuming every record must be owner-only.

How Does Automated API Scanning Help AI Developers?

Automated API scanning can identify supported patterns in reachable endpoints. It complements code review and authenticated workflow tests; it does not guarantee immediate detection of a newly deployed vulnerability.

SimplyScan reports across 8 dimensions. A URL scan can inspect supported public-resource signals, including:

  • Recognized secret patterns in files and scripts it inspects.
  • Selected Supabase exposure signals from available metadata and bounded probes.
  • Returned security headers.
  • Performance signals available from the fetched resources and supported measurements.

79% of the 125 live sites SimplyScan has scanned (99 sites) have at least one medium-severity speed issue, such as render-blocking scripts or no route-based code splitting.

A public URL scan does not exercise every login flow, inspect private server-side policies, or establish that all performance bottlenecks have been found.

Investigate findings, fix confirmed issues, and retest the relevant behavior. A clean scan is not a guarantee against a data breach.

Why Should You Monitor API Uptime and Health?

Security is not just about preventing hacks; it is also about availability. Uptime monitoring can alert you when configured checks detect an outage; it does not guarantee that you will be the first to notice.

Pro Monitoring includes Pro scan credits for full reports. See pricing for the allowance associated with your chosen option.

SimplyScan Pro Monitoring provides scheduled rescans and supported Slack/GitHub integrations. Its HTTP uptime checks provide an availability signal, not a diagnosis of slow-rate attacks or every failure inside an authenticated API workflow.

How Can You Share a Scan Result?

A verified security badge links to a dated scan's score and eligibility state, subject to the badge criteria. Share it as a record of that scan, not as proof that every API operation or private backend setting has been audited.

The SimplyScan MCP server exposes supported checks to compatible editors. URL scans require a target reachable by the scanner. The Pro local-code tool uploads selected source files for analysis; it does not mean code is checked without leaving your machine.

Summary of API Security Steps

Proxy your requests

Keep long-lived secret provider keys on the backend. Use browser credentials only when the provider explicitly supports that flow with appropriately scoped, short-lived credentials.

Audit your environment

Inspect source, build output, and relevant repository history for detectable secret patterns. Revoke exposed credentials and investigate usage. The environment-file linter checks supplied text for supported issues; it does not scan a repository or prove a deployment is secret-free.

Test database authorization

Test database rules for allowed and denied requests, including requests made as unauthenticated users and other accounts.

Scan regularly

Use SimplyScan for supported checks, investigate reported issues, and test behavior outside the scan's coverage.

Monitor Uptime

Monitor reachable endpoints and test the authenticated operations your users depend on. A successful HTTP response alone does not prove that the workflow is healthy.

Apply these controls to the provider, model, and tools your application actually uses, and revisit them when those integrations change.

Sources

Every figure above was checked against the page it cites · here they are, so you can check them too.

  1. As of May 2026, the OpenAI API provides access to the GPT-5 family (GPT-5.5 and GPT-5.5 Pro as flagships, plus GPT-5.4, GPT-5.4-mini, and GPT-5.4-nano) · metacto.com
  2. Agoda today announced the open-source release of its API Agent, a universal Model Context Protocol (MCP) server designed to help developers connect MCP clients to GraphQL and REST services · finance.yahoo.com

Frequently asked questions

API security covers authentication, authorization, input handling, secrets, and resource limits at your app's endpoints and provider connections. AI features also need controls over model inputs, outputs, and tool actions. No single proxy, filter, or scan establishes that the integration is secure.
Keep long-lived secret credentials out of browser code and client-facing environment variables. Use protected backend calls when a provider requires a secret key, enforce caller permissions and usage limits, and inspect deployed files and relevant repository history. Revoke exposed credentials and investigate usage; a clean scan does not prove none remain.
MCP can expose tools and data to compatible clients. Review the server, its transport and authorization, the credentials it receives, and each tool's permissions. Authentication alone does not establish that every tool action is appropriate for the requesting user.
Automated checks can help find supported exposure patterns and returned-header issues. SimplyScan URL scans inspect reachable public resources and selected probes; they do not replace private policy review, authenticated access tests, or a full API audit.
Postgres RLS applies row-level conditions to roles subject to it, alongside table privileges and other authorization controls. Test intended allowed and denied operations, including bypass roles. Firebase uses Security Rules rather than Postgres RLS.
Keep the secret OpenAI API key on the backend, validate requests, enforce user permissions, and set usage controls. Revoke exposed credentials and review provider usage. Follow the official API authentication and production guidance; model choice or a scan badge alone does not establish integration security.

Is your app secure? Run a free security scan in 30 seconds · no signup required.

Scan your app free →