Security & privacy
API key scoping, X-Api-Key, the same-origin proxy pattern, PII handling, and what the SDK never logs.
API keys
The SDK authenticates every request using a scoped API key sent as the X-Api-Key request header.
Keys are public in the browser
A key included in a browser bundle is visible to anyone who inspects the JS bundle or opens the network tab. This is expected and acceptable - provided the key is correctly scoped.
Only ever use keys that have the minimum permissions required for the client context:
- Browser / storefront: search and analytics read/write only. Never an admin or ingest key.
- Server / loader: can use a broader key because it is never exposed to the browser.
Never use an admin or ingest key in the browser. Issue a scoped key and rotate it if it is ever exposed.
Load keys from environment variables
Never commit an API key to source control. Load it from the build environment:
const kelp = createKelpClient({
searchUrl: import.meta.env.VITE_KELP_SEARCH_URL,
analyticsUrl: import.meta.env.VITE_KELP_ANALYTICS_URL,
apiKey: import.meta.env.VITE_KELP_API_KEY,
});Common variable names: VITE_KELP_API_KEY, PUBLIC_KELP_API_KEY, NEXT_PUBLIC_KELP_API_KEY.
Rotate compromised keys
If a key is accidentally committed or otherwise exposed, rotate it immediately in the Kelp dashboard and update your environment variables. The old key stops working as soon as it is revoked.
Same-origin proxy pattern
For tighter control in production, proxy analytics and search through your own server rather than hitting the Kelp hosts directly from the browser. This lets you:
- Attach the API key server-side so it is never sent to the browser at all.
- Apply rate limiting, logging, and authentication at the edge.
- Satisfy strict CSP policies that disallow third-party hosts.
Set searchUrl and analyticsUrl to an empty string (or a path on your origin), and attach the key in your proxy:
// Browser client - no key, no Kelp host exposed
const kelp = createKelpClient({
searchUrl: '', // -> /api/v1/collections/...
analyticsUrl: '', // -> /analytics/events
apiKey: '', // proxy attaches the real key
});// Server-side proxy (e.g. Express or Hydrogen loader)
app.all('/api/v1/*', (req, res) => {
fetch(`https://{TENANT_ID}-search.kelp.click${req.path}`, {
method: req.method,
headers: {
'Content-Type': 'application/json',
'X-Api-Key': process.env.KELP_API_KEY,
},
body: req.method !== 'GET' ? JSON.stringify(req.body) : undefined,
}).then(upstream => upstream.json()).then(data => res.json(data));
});The Shopify Hydrogen example app in the SDK repository ships a working same-origin proxy for analytics.
HTTPS
Always configure searchUrl and analyticsUrl with https:// URLs in production. The SDK does not enforce HTTPS - it will send the key and events over plain HTTP if configured that way.
Privacy and PII
What the SDK does not log
Regardless of the debug setting, the SDK never logs:
- The API key or any authorization header value.
- Full request or response bodies.
- User identity values (anonymous id, session id, user id).
Avoid PII in events and queries
Do not put email addresses, tokens, card numbers, or other personal data in q (the search query), filter values, or event payloads. These fields flow to analytics storage and logs.
Use the sanitizeEvent hook in createAnalytics to redact sensitive content before it leaves the browser:
const analytics = createAnalytics({
client: kelp,
identity,
sanitizeEvent(event) {
if (event.kind === 'search' && event.q) {
return { ...event, q: '[redacted]' };
}
return event;
},
});localStorage and XSS
Session IDs and anonymous IDs are stored in localStorage in cleartext. A compromised script on your origin can read them. They are not authentication credentials, but they are persistent identifiers.
Protect your origin against XSS with a strict Content-Security-Policy. If you need more control over storage (e.g. httpOnly cookies), implement KelpStorage and pass it to createIdentity:
import { createIdentity, type KelpStorage } from '@kelpclick/client';
const cookieStorage: KelpStorage = {
get: (k) => readCookie(k),
set: (k, v) => writeCookie(k, v, { secure: true, sameSite: 'Lax' }),
remove: (k) => deleteCookie(k),
};
const identity = createIdentity({ storage: cookieStorage });Related
- Client configuration -
apiKey,searchUrl,analyticsUrl - Observability - what is and is not logged
- Error handling -
'auth'error code for key issues