Skip to main content

Overview

Security is paramount when implementing webview authentication. This guide covers critical security considerations for both postMessage and query parameter methods.

IP Whitelisting

The Doshi API requires IP whitelisting. Contact hello@doshi.app to whitelist your server IP addresses.
To get your server’s IP address:
Send this IP address to hello@doshi.app along with your organization name.

API Key Security

Never expose your API key in client-side code. Always call the Doshi API from your backend server.

Secure API Key Usage

Backend Implementation Example

Origin Verification

Always verify the origin of messages in production environments
If you load the iframe from sandbox, the origin you verify here — and the targetOrigin you pass to postMessage — must be https://sandbox.embed.doshi.app. A check hardcoded to the production host will silently reject sandbox messages. Allow both hosts to support either environment. See Environments.

For postMessage

Specify Target Origins

Token Security

Token Lifecycle

The custom token received from the API:
  • Is single-use for initial authentication
  • Has a short expiration time
  • Cannot be reused after the user session is established

Session Tokens

Once authenticated:
  • ID Token TTL: 1 hour
  • Refresh Token TTL: 12 hours
  • The iframe manages token refresh automatically
  • Sessions are isolated per iframe instance

Cross-Origin Communication

postMessage API Security

Always validate the structure and content of messages:
Implement comprehensive error handling:
Always use HTTPS for secure communication:

Query Parameter Security

Query parameters are visible in URLs and browser history. The custom token is short-lived but still sensitive.

Best Practices

  1. Clear Parameters After Use
  1. Use Short-Lived Tokens
The custom token from the API is already short-lived, but you can add additional validation:
  1. Monitor Token Usage
  1. Respect URL Length Limits
URLs should generally stay under 2000 characters for maximum browser compatibility

2FA Security

When implementing 2FA:

Don’t Send Unnecessary Data

Security Checklist

Store API key securely in backend environment variables
Never expose API key in client-side code
Call Doshi API only from your backend server
Use HTTPS for all communication
Verify message origins in production
Never use ”*” wildcard for target origins in production
Validate all incoming messages and parameters
Use short-lived tokens
Clear sensitive data from URLs after reading
Implement comprehensive error handling
Log security events for monitoring
Test across different browsers and environments

Common Security Pitfalls

Environment-Specific Configuration

Monitoring and Logging

Next Steps

postMessage Implementation

Implement secure real-time authentication

Query Parameters

Use URL-based authentication safely