惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
Security Latest
Security Latest
P
Proofpoint News Feed
GbyAI
GbyAI
PCI Perspectives
PCI Perspectives
博客园 - Franky
N
Netflix TechBlog - Medium
博客园_首页
WordPress大学
WordPress大学
K
Kaspersky official blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Vercel News
Vercel News
T
Threatpost
The Hacker News
The Hacker News
H
Help Net Security
S
Securelist
Recent Announcements
Recent Announcements
腾讯CDC
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Engineering at Meta
Engineering at Meta
C
Cisco Blogs
V
V2EX
C
Check Point Blog
S
Schneier on Security
Cyberwarzone
Cyberwarzone
C
Cybersecurity and Infrastructure Security Agency CISA
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Jina AI
Jina AI
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
博客园 - 叶小钗
A
Arctic Wolf
AWS News Blog
AWS News Blog
Latest news
Latest news
Martin Fowler
Martin Fowler
Recorded Future
Recorded Future
Last Week in AI
Last Week in AI
The GitHub Blog
The GitHub Blog
小众软件
小众软件
B
Blog
aimingoo的专栏
aimingoo的专栏
C
Cyber Attacks, Cyber Crime and Cyber Security
V
Visual Studio Blog
P
Palo Alto Networks Blog
Spread Privacy
Spread Privacy

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything BFF模式详解:构建前后端协同的中间层 I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Firebase AI Logic Is on the Client. Here Are the 4 Security Layers That Keep It Safe.
Nimra Abid · 2026-05-24 · via DEV Community

This is a submission for the Google I/O Writing Challenge


Firebase AI Logic is genuinely exciting. It went GA at Google I/O 2026, meaning you can call Gemini directly from your web or mobile app: no backend server, no API key in your bundle, no infrastructure to manage. The developer experience is real.

But putting an AI endpoint on the internet creates an attack surface. And most of the posts I have read including some in this challenge — cover only one of the security mechanisms Google shipped.

There are four. They compose. This post walks through all of them.


The Threat Model: What You Are Actually Defending Against

Before any code, let's be precise about what can go wrong.

Quota exhaustion anyone who finds your endpoint and scripts against it drains your token budget. Every AI call has a direct billing impact.

Prompt injection if your system instructions live in client code, they can be extracted through binary decompilation or network interception and then exploited.

Token replay even short-lived auth tokens can be intercepted and reused. A 5-minute window is enough for a script to hammer your endpoint.

Unsafe content at inference time user inputs that reach the model are not sanitized by default. Without enforcement at the inference layer, adversarial inputs can get through.

Each of the four layers I'm about to show you closes one of these gaps directly.


Layer 1: The Proxy Architecture

Closes: quota exhaustion via API key theft

The naive approach embed your Gemini API key in the app bundle and call the API directly will eventually fail. App bundles are decompilable. Network traffic is observable.

Firebase AI Logic solves this at the architecture level. Every SDK request routes through Firebase's proxy servers. Your Gemini API key lives on Firebase's infrastructure and is never transmitted to the client.

// firebase.ts
import { initializeApp, FirebaseApp } from 'firebase/app';
import { getAI, GoogleAIBackend, AI } from 'firebase/ai';

const firebaseConfig = {
  apiKey: "your-firebase-api-key",            // ✅ Firebase Web API key — safe in client.
  authDomain: "your-project.firebaseapp.com", // This is a project identifier,
  projectId: "your-project-id",               // NOT a billing credential.
  appId: "your-app-id"
};

const app: FirebaseApp = initializeApp(firebaseConfig);

// All requests route through Firebase's proxy.
// Your Gemini API key never leaves Firebase's servers.
const ai: AI = getAI(app, { backend: new GoogleAIBackend() });

export { app, ai };

Enter fullscreen mode Exit fullscreen mode

The Firebase Web API key is not a secret — it is a project identifier scoped by your security rules. Your Gemini API key, which carries billing authority, never appears in your codebase.


Layer 2: Server Prompt Templates + Template-Only Mode

Closes: prompt injection and prompt extraction

If your system instructions live in client code, two things can go wrong:

  1. Anyone who decompiles your app binary can read your exact prompt.
  2. If you compose prompts dynamically from user input, a determined user can craft inputs designed to override your system instructions. Server prompt templates move your entire prompt configuration — system instructions, model selection, safety settings, input schemas — to Firebase's servers. The client sends only a template ID and typed variable values.

Template-Only Mode, announced at I/O 2026, enforces this strictly: Firebase AI Logic will only execute prompts stored on the server. Any custom prompt instructions sent directly from client code are ignored entirely.

Templates are defined in the Firebase console using Dotprompt syntax:

---
model: gemini-3.1-flash
config:
  temperature: 0.4
  topP: 0.9
input:
  schema:
    userQuery: string
    userName?: string
---
{{role "system"}}
You are a professional support agent for Acme Corp.
You answer questions about orders, returns, and shipping only.
You do not engage with topics outside these areas.

{{role "user"}}
{{#if userName}}Customer {{userName}} asks:{{/if}}
{{userQuery}}

Enter fullscreen mode Exit fullscreen mode

Everything above — model, config, system instructions, input schema — lives on Firebase's servers. On the client, use getTemplateGenerativeModel() as specified in the official JS SDK reference:

// secure-chat.ts
import { getAI, GoogleAIBackend, getTemplateGenerativeModel } from 'firebase/ai';
import { app } from './firebase';

// Typed interface matching the template's input schema.
// Enforced at compile time — no undeclared fields can reach the template.
interface SupportTemplateVariables {
  userQuery: string;
  userName?: string;
}

const ai = getAI(app, { backend: new GoogleAIBackend() });

// Must use getTemplateGenerativeModel() — not ai.templateGenerativeModel()
const templateModel = getTemplateGenerativeModel(ai);

export async function askSupportAgent(
  userInput: string,
  displayName?: string
): Promise<string> {
  const variables: SupportTemplateVariables = {
    userQuery: userInput,
    userName: displayName ?? undefined,
  };

  // Client sends only: template ID + typed variable values.
  // System instructions, model config, and safety settings
  // are composed server-side and never reach the client.
  const result = await templateModel.generateContent(
    'support-agent-v2',
    variables
  );

  return result.response.text();
}

Enter fullscreen mode Exit fullscreen mode

Note what is absent from the client code: no system prompt, no model name, no safety configuration. None of those are available to read, modify, or override. With Template-Only Mode enabled, this is the only kind of request Firebase AI Logic will accept from your app.

The TypeScript interface matters beyond type safety — it makes the contract between client and server explicit and compiler-enforced. If a developer tries to pass an unintended field that could leak into the prompt, the compiler catches it before it ships.


Layer 3: Firebase App Check + Replay Attack Protection

Closes: unauthorized clients and token replay

Template-Only Mode secures the content of your prompts. App Check addresses who is allowed to send requests in the first place.

App Check uses device attestation providers — Play Integrity on Android, DeviceCheck on Apple, and reCAPTCHA Enterprise on web — to generate cryptographic tokens proving a request came from a genuine, unmodified instance of your app. Firebase validates these tokens before processing any AI request.

// app-check.ts
import { initializeAppCheck, ReCaptchaEnterpriseProvider, AppCheck } from 'firebase/app-check';
import { FirebaseApp } from 'firebase/app';
import { app } from './firebase';

export function initializeSecureAppCheck(app: FirebaseApp): AppCheck {
  return initializeAppCheck(app, {
    provider: new ReCaptchaEnterpriseProvider(
      import.meta.env.VITE_RECAPTCHA_ENTERPRISE_SITE_KEY
    ),
    // The SDK automatically attaches a fresh App Check token
    // to every outgoing Firebase request — no manual token
    // management needed anywhere in your app.
    isTokenAutoRefreshEnabled: true,
  });
}

Enter fullscreen mode Exit fullscreen mode

// main.ts — call this once before any Firebase AI Logic requests
import { initializeSecureAppCheck } from './app-check';
import { app } from './firebase';

initializeSecureAppCheck(app);

Enter fullscreen mode Exit fullscreen mode

Replay attack protection, which shipped in May 2026, closes the remaining gap. Even with short-lived tokens App Check already supported lifespans as short as 5 minutes an intercepted token can be reused within its validity window. For AI endpoints billed per token, that window is exploitable.

With replay protection enabled, each App Check token is strictly single-use. The first request that presents a token consumes it permanently. Any subsequent request with the same token is rejected immediately.

Enable replay protection in the Firebase console under App Check → [your app] → Limited-use tokens. No client code changes beyond the initialization above.


Layer 4: Model Armor — GA with Firebase

Closes: unsafe content at inference time

The previous three layers secure authentication and prompt structure. Model Armor addresses what actually reaches the model at inference time.

Google Model Armor reached general availability with Firebase at Cloud Next 2026. It operates as an enforcement layer between your Firebase AI Logic request and the Gemini API — inspecting both the prompt being sent to the model and the response being returned. Configurable guardrails cover harmful content, prompt injection attempts, sensitive data patterns, and custom policy rules.

The key characteristic of the Firebase integration: it requires zero changes to your application code. Model Armor is configured at the Firebase project level in the Google Cloud console. Your SDK calls pass through it transparently.

// Your application code is identical with or without Model Armor.
// Enforcement happens at the Firebase infrastructure layer.

export async function askSupportAgent(
  userInput: string,
  displayName?: string
): Promise<string | null> {
  const variables: SupportTemplateVariables = {
    userQuery: userInput,
    userName: displayName,
  };

  try {
    const result = await templateModel.generateContent(
      'support-agent-v2',
      variables
    );
    return result.response.text();

  } catch (error: unknown) {
    // If Model Armor intercepted the input or output as a policy violation,
    // Firebase returns an error before the model processes it.
    // You handle the error — not the unsafe content.
    if (error instanceof Error) {
      console.error('Request blocked by content policy:', error.message);
    }
    return null;
  }
}

Enter fullscreen mode Exit fullscreen mode

Guardrails content categories, sensitivity thresholds, custom filters are managed through the Google Cloud console. You can update them without touching client code or releasing an app update.


What the Full Stack Looks Like End to End

User submits input
        │
        ▼ TypeScript interface — typed variables enforced at compile time
        │
        ▼ Firebase SDK — App Check token automatically attached
        │
        ▼ Firebase Proxy — token validated; replay check (single-use)
                         — Gemini API key never leaves server ✓
        │
        ▼ Firebase AI Logic — Template-Only Mode enforced
                            — Server template composed, not client prompt ✓
        │
        ▼ Model Armor — input inspected against guardrails ✓
        │
        ▼ Gemini API — processes sanitized, policy-compliant prompt
        │
        ▼ Model Armor — response inspected before return
        │
        ▼ Your app receives a clean, policy-compliant response ✓

Enter fullscreen mode Exit fullscreen mode

An attacker who extracts your binary finds no API key and no system prompt. An attacker who scripts requests finds their tokens rejected after first use. An attacker who crafts adversarial inputs finds them stopped before the model.


What Is Still Your Responsibility

These four layers are not a complete story on their own.

Firestore Security Rules Firebase AI Logic secures the AI inference path. If you store conversation history or user data in Firestore, your Security Rules govern who can access it. A secured AI feature in front of an open database is still a vulnerability.

Firebase Authentication App Check verifies that a request comes from your app. It does not verify which user is making it. If your AI feature should only be accessible to authenticated users, Firebase Authentication provides that boundary.

Your own output handling Model Armor filters content at the infrastructure layer. Your application still needs to handle model responses safely rendering output correctly, not blindly executing model suggestions, and validating AI-generated content before treating it as trusted data.


The Bigger Picture

The features Google shipped across Cloud Next 2026 and I/O 2026 make something clear: they built the security infrastructure alongside the capability, not as an afterthought.

The proxy architecture, Template-Only Mode, App Check replay protection, and Model Armor are not independent features. They are a layered answer to a single question: how do you ship an AI feature in a client app that a serious engineering team can stand behind?

The developers who answer that question well will be the ones who implement all four layers not just the ones their quickstart tutorial covered.

All four are available to you today.


Note on TemplateGenerativeModel: As of the JS SDK reference dated May 2026, this class is in Public Preview and the API shape may evolve. Always instantiate via getTemplateGenerativeModel(ai) — not ai.templateGenerativeModel(). Check the official reference before shipping.


Sources: Firebase AI Logic docs · What's new from Firebase at Google I/O 2026 · Ship production AI features faster — Cloud Next '26 · Server prompt templates: get started · TemplateGenerativeModel JS API reference