SearchFn
Operations

Security

Authorization, secret handling, and credential management for SearchFn.

Authorization

createSearchFnServer supports a per-action authorize callback. It is called before every operation with the request context, action name, and payload:

const server = await createSearchFnServer({
  adapter,
  authorize: async (ctx, action, payload) => {
    if (action === "status") return true;
    if (action === "search" || action === "searchAll") return !!ctx.user;
    return ctx.user?.role === "admin";
  },
});

Actions

ActionEndpointTypical policy
statusGET /searchfn/statusAllow all (health checks)
searchPOST /searchfn/searchAuthenticated users
searchAllPOST /searchfn/search-allAuthenticated users
indexPOST /searchfn/indexAdmin or service accounts
removePOST /searchfn/removeAdmin or service accounts
clearPOST /searchfn/clearAdmin only

Unauthorized requests return a FORBIDDEN error envelope with no details about the denial reason.

Secret Redaction

The server automatically redacts sensitive values in structured logs. The following keys are recursively redacted:

  • apiKey
  • password
  • secret
  • token
  • authorization
  • connectionString

Error responses never include backend credentials, connection strings, or internal stack traces.

Credential Management

AdapterCredentialStorage recommendation
PostgresAdapterConnection string (DSN)Secure secret store or encrypted environment variable
MeilisearchAdapterAPI keyEnvironment-level secret
Elasticsearch/OpenSearchAPI key or username/passwordSecure runtime secret store

Never hardcode credentials in application code. Use environment variables at minimum, and a dedicated secret manager (AWS Secrets Manager, HashiCorp Vault, etc.) for production deployments.