Hey bugs, I know it’s been a while.
Lately, I’ve been experimenting with building small hacking-inspired tools. My latest creation is a “vibe-coded” security helper which is an app that uses AI to detect potential vulnerabilities in source code and offer quick insights. Think of it as a playful but useful tool for developers who want a first-pass security check.
Press enter or click to view image in full size
To make it work, I built the frontend with Lovable, tapped into Gemini’s API for AI-powered analysis, and used Cloudflare Workers to keep my API key locked down and secure.
If you’re looking for a hands-on example of connecting an AI model securely to a front-end app, this guide is for you.
We’ll let users paste in code snippets, send them securely to the Gemini model for vulnerability analysis — without ever exposing the Gemini API key to the browser.
Normally, if you connect directly from the frontend to Gemini’s API, you’d need to expose your API key — not good.
Cloudflare Workers act as a secure middle layer:
Browser <--> Cloudflare Worker <--> Gemini API
This way:
gemini-proxy
).wrangler secret put GEMINI_API_KEY
4. Add the Worker code (example below).
export default {
async fetch(request, env) {
if (request.method !== 'POST') {
return new Response('Only POST allowed', { status: 405 });
}
export default {
async fetch(request, env) {
if (request.method !== 'POST') {
return new Response('Only POST allowed', { status: 405 });
} // Get the JSON body from the frontend
const body = await request.json();
const codeSnippet = body.code; // user-submitted code snippet
// Forward request to Gemini API securely
const geminiResponse = await fetch('https://api.gemini.com/v1/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${env.GEMINI_API_KEY}`,
},
body: JSON.stringify({
prompt: `Analyze the following code for security vulnerabilities:\n\n${codeSnippet}`,
max_tokens: 200
})
});
const result = await geminiResponse.json();
return new Response(JSON.stringify(result), {
headers: { 'Content-Type': 'application/json' }
});
},
};
This Worker does three things:
In Lovable:
async function analyzeCode(code) {
const res = await fetch('https://your-worker-url.workers.dev', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ code })
});
const data = await res.json();
// Display Gemini’s response in your Lovable app
return data;
}
Because the Worker is public, but the key stays hidden, your front-end is safe.
You now have:
Users just paste code and get instant AI-powered insights, while your keys stay private and safe.
Hope you liked this one, feel free to build your own tool based off this template and feel free to share it!