Relay
Relay is a network proxy that encrypts and decrypts sensitive data in transit between a client and a destination server. It works with your own APIs and third-party services, and requires minimal changes to your existing code.
How Relay works
You can use Relay in a few ways.
Outbound from your server
You hold encrypted data (such as card details) and forward it to a third-party API. Relay decrypts the data as the request passes through it, so your infrastructure never handles sensitive data directly.
Inbound to your server
Data arrives from an external source and needs to be encrypted before it reaches your server. Relay encrypts the fields you specify on the way in.
Outbound to your frontend
Encrypted card details are decrypted on the way out, so they can be displayed to customers in a browser through the Reveal component.
Relay is most commonly used for outbound decryption. Here's what that looks like for collecting and sharing card data for a payment.
Collect
Your customer enters their card details into the Card component. The data is encrypted within the iframe before it's returned to your application.
Store
Your backend receives and stores the encrypted card information. Because the data is encrypted, it's safe to store on your side.
Send
Using the encrypted data, you send an API request through Relay to your payment processor.
Decrypt
Relay detects the encrypted card fields and decrypts them in transit.
Process
The payment processor receives the card data in plaintext and completes the payment. The response is piped back to you through Relay.
Evervault doesn't do anything with the response from your payment processor. If needed, you can configure Relay to encrypt any sensitive values before the response is forwarded to your server.
Getting started
This example focuses on creating a Relay and how you can send encrypted data through it. See the Card Collection page for an end-to-end guide that covers collecting, encrypting, and forwarding card data.
Encrypt and decrypt actions are tied to app keys. If you encrypt data with Relay in a sandbox app, you can't decrypt that data with Relay from a production app (or the other way around). Data can only be encrypted and decrypted using the same app key.
Create a Relay
Open the Relays section in the dashboard and click Create Relay. Provide the base URL (example.com) for the API you want to proxy requests to and create the Relay.
Evervault provisions a domain for your Relay after creating it. This is the domain you send requests to when you want to proxy API calls to downstream partners. The domain is built from the destination domain and your app ID, with dots and underscores replaced by hyphens. For example, a Relay to api.example.com for an app with an ID of app_1234567890 gets the domain api-example-com-app-1234567890.relay.evervault.app. You can find the exact domain in the Dashboard.
Configure a route
Routes define what to do with requests that match a given URL path, and you can have multiple routes for each Relay. You configure the data type and fields (JSON, form data, etc.) to operate on, as well as what to do with that data. To create a route, click + Add Route in the dashboard and then set the path (e.g., /charge), actions, etc.
You configure Relays to encrypt or decrypt data with route actions. These actions can be applied to requests (data being sent to the destination) or the response (data being returned to you). The combination you configure depends on your use case.
- Decrypt on request: your backend holds encrypted data and forwards it to a third-party API. Relay decrypts the fields in transit.
- Decrypt on response: used with the Reveal component to display card details to your customers.
- Encrypt on request: Encrypt data that you collect before storing it (outside of card data which you should use our card collection for)
- Encrypt on response: encrypt data returned by a third party, such as a card issuer returning PANs, before it reaches your server.
Sending a request
Pass your Relay's domain into your requests to proxy them to the target endpoint.
You can include a traceparent header on requests sent through Relay to correlate them with events in your own systems. Relay passes the header through to the destination and records its trace ID in Evervault's logs, so you can look up a request later. Learn more about correlation IDs.
As an example, when you collect a card number with Evervault, it's encrypted on the frontend before being sent to your backend. So a card number like 4242 4242 4242 4242 is turned into something like this.
You store this value instead of the plaintext card number. When you want to charge the card, you send the request through Relay with the encrypted string. Relay decrypts it in transit, and your downstream partner receives the plaintext card number.
Path matching
Route actions will only be applied to requests that match the request path. Paths can be configured to match a specific path or multiple paths with a wildcard.
| Example | Description |
|---|---|
/ | Matches requests to the root path |
/checkout | Matches requests to /checkout |
/patients/*/reports | Allows for dynamic URL segments such as IDs. Matches requests such as /patients/1/reports, /patients/2/reports, etc. |
/** | Matches all requests |
Selecting fields
Route actions are only applied to data that matches the list of selected fields defined on an action. Field selection can be configured on a per-content type basis.
JSON
Use JSONPath to select fields according to their path in the JSON object. JSON values must only contain encrypted strings (e.g., { "ssn": "ev:...1a2bc$" }). If the value contains other data like raw text (e.g.,{ "ssn": "User SSN: ev:...1a2bc$" }), decryption fails.
JSON payloads are supported for requests where the content-type subtype is JSON. The subtype is the part of the content-type header after the /. For example, a content-type of application/json+charset=utf8 has a subtype of JSON.
JSON selector examples
| Example | Description |
|---|---|
$.name | Matches the name field |
$.address.* | Matches all fields inside of the address object |
$.patients.*.name | Select the name field in all patients objects |
$.patients[?(@.country == 'IE')].name | Selects the |
$..* | Selects all fields inside the JSON object |
Form data
Form data is only supported for requests with a content-type of application/x-www-form-urlencoded or multipart/form-data. Form fields are matched directly by name. If a matched value contains multiple pieces of encrypted text, each one is decrypted individually. Global wildcards are supported for form data but not nested ones (e.g., * is valid but something like name.*.last isn't).
Wildcard selectors also decrypt encrypted files
An * form-field decrypt selector also decrypts encrypted files that arrive as octet-streams, including file parts in multipart/form-data. This unlocks file-decryption flows and deviates from the field-level model used elsewhere. Only Evervault-encrypted files are decrypted, so plain, non-encrypted octet-streams pass through untouched.
Form data selector examples
| Example | Description |
|---|---|
card[cvc] | Matches the card[cvc] field |
card[number] | Matches the card[number] field |
* | Matches all fields |
Files
Relay supports encrypting and decrypting files in multipart and form-data requests. Encrypted files are forwarded with an unchanged filename, but the bytes in the file are fully encrypted. There is a per-request limit of 25 MB for encryption and decryption.
An * form data decrypt selector also matches encrypted files, so it isn't always necessary to configure a separate file selector.
File selector examples
| Example | Description |
|---|---|
passport-scan | Matches files named passport-scan |
* | Matches all files |
Headers
Headers can be selected by name and aren't case sensitive. If the matched header value contains multiple pieces of encrypted text, each one is decrypted individually.
Header selector examples
| Example | Description |
|---|---|
Authorization | Matches the header named Authorization |
* | Matches all headers |
XML
To work with XML data, configure your Relay for JSON and select the fields to encrypt or decrypt using standard JSONPath. To encrypt attributes, use advanced JSONPath selectors. Relay converts repeated XML elements into an array named after the element, so include the element name before a wildcard. In the example data, the department elements become the array $.company.departments.department.
XML selector examples
| Example | Description |
|---|---|
$.company.revenue | Matches the revenue element |
$.company.departments.department.*.employees.employee.salary | Wildcard selector that matches the salary field for every employee across all departments |
$.company.departments.department.*['@name'] | Matches the department name attribute |
Access controls
These settings control who can send requests through your Relay, which requests it forwards to the destination, and how it authenticates with the destination.
Authentication
API key authentication adds an additional layer of security to your Relay. When enabled, requests through Relay require a valid Evervault API key in the X-Evervault-Api-Key header and your app's ID in the X-Evervault-App-Id header.
Enable authentication for Relays that decrypt data
Evervault strongly recommends enabling API key authentication for any Relay configured to decrypt data. If your Relay is pointed at your own API (which already has its own authentication), it may not be strictly necessary. When using Relay with a third-party API, API key authentication ensures that only your application can trigger decryption.
You can enable authentication for your Relay in the Evervault Dashboard by navigating to the Authentication settings page.
Authorize access to decrypted data
Some flows deliver decrypted data directly to a client (e.g., the Card Reveal iframe fetching plaintext card data). In these cases, your backend endpoint is the only place where access control is enforced. Evervault has no context for which of your customers can access a given record, so authenticate the request and verify that the caller is authorized before the response is returned.
mTLS
mTLS (mutual TLS) lets Relay authenticate with the target server using a client certificate, adding an additional layer of transport security between Relay and the downstream service. This is typically only required by organizations with strict security policies that mandate mutual authentication at the network layer — most integrations don't need it.
mTLS must be enabled by Evervault. Contact support@evervault.com to request it for your Relay.
Traffic forwarding
By default, a Relay forwards every request to the destination and uses route actions to encrypt or decrypt data where a route matches. You can optionally set Relay to deny requests that don't match a pattern you expect, before they reach the destination. Denying these requests reduces load and blocks spam. How this helps depends on where the Relay sits:
- In front of an API you own, it stops spam and other unexpected requests from reaching your service through Evervault.
- In front of a third-party API, it limits your use of that API to the requests you expect to send.
To deny unexpected requests, set the Relay's traffic forwarding mode to closed. A closed Relay only forwards requests when the method and path of the request match a route that has a request or response action. If there's no match, the request isn't forwarded, and nothing is encrypted or decrypted. A closed Relay also follows these rules:
- An
OPTIONSrequest is forwarded when a route of any method matches its path, so CORS preflight requests still reach the destination. - A
HEADrequest is forwarded when aGETroute matches its path. - Every other request gets a
403response with theforbiddenerror code. Other permission failures return the same response, so your client can't tell them apart. Relay logs the denied request with the error codetraffic-forwarding-denied. - A closed Relay with no routes denies every request.
- On a Relay with API key authentication, a request without valid credentials gets a
401response before Relay checks the routes.
New Relays are open, and you can't set the mode when you create a Relay. To change the mode of an existing Relay, update it to set the trafficForwardingMode attribute:
You can also change the mode in the Relay's settings in the Evervault Dashboard.
Limitations
The following limitations apply to all requests sent through Relay. If your application requires higher limits, contact support@evervault.com to discuss your requirements.
| Description | Limit |
|---|---|
| Max payload size | 5mb |
| Max file size | 25mb |
| Request timeout (end to end) | 120s |
Alerts
Alerts allow you to see errors in Slack or be sent to any webhook URL of your choice. You can create an alert for your Relay inside of the Evervault Dashboard by navigating to Relay → Alerts → Add Alert. When you configure a custom webhook to receive alerts, the following fields will be in the response.
Payload
A message that names the Relay domain where the error occurred, for example
An error occurred in your Relay: api-example-com-app-1234567890.relay.evervault.app.A link to the logs of your app in the Evervault Dashboard.
ERRif Relay raised the error. Otherwise,4XXor5XXto match the status code of the response.The time Relay logged the request, in milliseconds since the Unix epoch, as a string.
- The unique identifier for your team.
- The unique identifier for your app.
- The unique identifier for your Relay.
- The Relay domain that received the request.
The destination URL of the request. This attribute isn't present if Relay failed before it built the request to the destination.
Error handling
Errors originating from within Relay can be distinguished by the X-Evervault-Error-Code header. The responses have a content type of application/problem+json and a body with the HTTP status code, the error code, a human-readable title, and a longer detail. For example:
Error Codes
There was an issue finding a Relay for the provided domain. Double-check your Relay configuration, including the domain.
The request took longer than the 120-second request timeout.
This error occurs when Relay is configured to perform response encryption and receives an unsupported content type as a response from the endpoint. Currently, Relay can only encrypt JSON, XML, and multipart/form-data structured data.
The Relay has API key authentication enabled, and the request doesn't have valid credentials. Send a valid API key in the
X-Evervault-Api-Keyheader and your app ID in theX-Evervault-App-Idheader. Relay also returns this code when a Relay requires a client certificate and the request doesn't have one.Relay refused the request. The API key doesn't have the permissions that the Relay needs, the client certificate isn't valid for this Relay, the app is suspended, or the Relay is configured to deny the request based on traffic forwarding rules. Review the permissions of your API key in the Evervault Dashboard.
This error indicates that an invalid hostname was provided while communicating with Relay in forward proxy mode. Ensure you have entered the downstream hostname correctly, and that it can be resolved when requesting it directly.
This request exceeds the request size limit in Relay. The current per-request limit is 25 MB for encryption/decryption of multipart data, and 5 MB for all other content types. The response body has a
maxSizeattribute with the limit that applied, in bytes.The content type header received by Relay was malformed, preventing the body from being processed.
There was an issue with Relay itself. Try again in a few moments.
A ciphertext's data policy prevented it from being decrypted. Ensure your data policy's configuration is correct.
This error indicates that Relay received a CONNECT request with no hostname while operating in forward proxy mode. Ensure you have entered the downstream hostname correctly, and that it can be resolved when requesting it directly.
There was encrypted data where it wasn't expected. This can mean a number of things:
- An inbound request header value contained Evervault encrypted data.
- An inbound request payload had Evervault encrypted data as the value of one of the fields, which wasn't going to be encrypted.
- The target URI for the inbound request had Evervault encrypted data as part of the path.
Relay experienced an unexpected networking error while communicating with the downstream service. This includes a downstream service that refuses the connection, can't be reached, or fails the TLS handshake. Please confirm that the downstream service is accessible when not routing through Relay, and ensure that any allowlist requirements have been met.
Relay received a request using the CONNECT method which is only supported in forward proxy mode.
The server is unable (or refuses) to process the request sent by the client, due to an issue that's perceived by the server to be a client problem. For example, Relay can't decrypt data that was encrypted by a different app.
Relay is in forward proxy mode, and the request doesn't have valid credentials in the
Proxy-Authorizationheader. A Relay with API key authentication returnsunauthorizedinstead.
Custom domains
Each Relay is provisioned with its own unique relay.evervault.app domain. You can also configure additional custom domains for your Relay in the Evervault Dashboard by navigating to Relay → Settings → Domains.
To add a custom domain, add the DNS records that the Dashboard shows for your domain to your DNS provider. The records are a CNAME record that points to custom-dns.relay.evervault.app and, by default, an ownership validation TXT record on the _ev-custom-domain subdomain of your custom domain. For some domains, Evervault validates ownership through its certificate provider, and the Dashboard shows that provider's TXT record name and value instead. For domains that Evervault validates over HTTP, you don't need a TXT record.
DNS propagation can take anywhere from a few minutes to 24 hours depending on your DNS provider and the TTL settings on your domain. If your custom domain isn't resolving after adding the records, check that every record the Dashboard shows has been added correctly and allow more time for propagation.
Alternative configurations
These configurations are possible with Evervault, but not generally recommended. They're only used in specific situations where the default options aren't adequate.
Forward proxy mode
The integration described above is sufficient for most use cases, but there are some scenarios where you might need to use Relay in forward proxy mode (e.g., you can't change the hostname used by a third party library). Forward proxy mode requires installing the Relay certificate chain, and configuring the relevant traffic to route using Evervault Relay acting as an HTTP CONNECT proxy.
To integrate with Relay in forward-proxy mode, you need to:
- Trust the Relay cert chain on your server. The cert can be obtained from ca.evervault.com.
- Identify the best approach for establishing an HTTP tunnel in your preferred language.
- For example, in Node.js this is likely using an Agent (which can be created using the Evervault Node.js SDK), or in JVM-based languages this is through the VM's
http.proxyHostconfiguration options.
- For example, in Node.js this is likely using an Agent (which can be created using the Evervault Node.js SDK), or in JVM-based languages this is through the VM's
- Supply your proxy authentication credentials to Relay using basic auth. This can be done during either the initial
CONNECTrequest or the subsequent proxied request using theProxy-Authorizationheader. The value should be basic auth credentials, with your app ID as the username and your API key as the password.- Relay only proxies requests to hosts that have been explicitly created in your app and can't be treated as a generic forward proxy.
You can test Relay as a forward proxy using curl:
Using fixed regions
Using fixed regions isn't generally recommended and Evervault doesn't guarantee reliability or provide an SLA when using a fixed region.
Evervault operates an active-active infrastructure across multiple regions and availability zones. If you need to, you can specify specific regions (either us or eu) to use with Relay, but this doesn't come with an SLA from Evervault's side. To do this, add us or eu to your Relay URL when making a call. For example, if your base URL is your-prod-app-12345.relay.evervault.app, change it to your-prod-app-12345.us.relay.evervault.app to send requests to the US region.