Skip to main content

Overview

URL validation lets SEARCH v4 confirm that the URL it receives is exactly the URL you created. You add a validation parameter, calculated from the URL and your private key with SHA-256. SEARCH v4 recalculates the value internally. If it matches, the request is processed. If it does not, the request is rejected. Nothing needs to be integrated on the receiving side. You only need to generate the validation value and call the resulting URL from your client-side script.

What it protects against

Validation is designed to catch changes made to the URL after you create it and before SEARCH v4 receives it, for example by a redirect or another intermediary in the path. If the URL is altered in any way, the validation no longer matches and the request is rejected. It relies on your private key staying secret. Anyone who has the key can create a valid validation value, so see Protecting your private key.
URL validation is available exclusively for SEARCH v4, and only for clients that have it enabled. When it is enabled, a request without the validation parameter fails with the message Required parameter(s) : validation should be provided.

How the validation value is calculated

1

Build the full URL

Use the complete URL, including the scheme, host, path, and every query parameter, in the exact order you will send them. Do not include validation yet.
2

Append your private key

Add your private key directly to the end of the URL, with no separator.
3

Calculate SHA-256

Hash the combined string as UTF-8. The result is a 64-character lowercase hexadecimal string.
4

Add it as the last parameter

Append &validation= followed by the hash to the original URL. Call that URL exactly as it is.
Any change to the URL after it is signed, such as reordering parameters, adding a parameter, or changing the host, makes the validation fail. Sign the final URL and call it unchanged.

Manual example

You can try the process by hand, for example to test your integration.
Without the validation parameter, the same request returns the error message above. With it, the request returns the normal search result.

Protecting your private key

Your private key is a secret. Anyone who has it can create a valid validation value for any URL. This integration runs in the respondent’s browser, and anything in client-side code can be read. The sample below keeps the key in a constant for demonstration only. How your integration provides the private key to the script without exposing it is up to you, so decide this before you go live.
Do not treat the sample’s PRIVATE_KEY constant as a way to protect the key. If the key can be read from your page, it can be used to sign changed URLs.

How it works

Prerequisites

  • A Research Defender publishable key, used for the library and in the URL path
  • A Research Defender private key, used to calculate validation
  • A client account with URL validation enabled for SEARCH v4
  • Your survey number (sy_nr) and the respondent’s session ID (sn_ud)
  • A page served over HTTPS, or http://localhost for testing. The browser’s SHA-256 function is only available in a secure context, so opening the file directly from disk (file://) will not work.

Request

string
GET https://{environment}.rtymgt.com/api/v4/respondents/search/{publishable_key}
string
required
The SHA-256 validation value, as 64 lowercase hexadecimal characters. It must be the last parameter.
string
required
The survey number.
string
required
The respondent’s session ID.
string
Set to "1" to enable.
string
Set to "1" to enable.
string
required
The string returned by pass_params(). Send it as the name of a query parameter with an empty value.
Every parameter you send is part of the signed URL. If you add another parameter, for example encrypt=1 for an encrypted response, add it in buildSearchUrl() so it is included before the URL is signed.

Browser integration

  • collectLibraryData() is the same function used in the advanced integration.
  • buildSearchUrl() builds the URL with the parameters in a fixed order and percent-encodes each name and value.
  • signUrl() calculates validation with the browser’s built-in crypto.subtle and appends it as the last parameter.
  • search() calls the signed URL exactly as built, with credentials included so Research Defender cookies are sent.

Full HTML page

validated-client.html
Replace the placeholder values at the top of the script, then serve the file over HTTPS or http://localhost.

Security recommendations

  • Treat the private key as a secret. Decide how your script receives it without exposing it, and never commit it to source control.
  • Do not log the private key or the string you hash.
  • Sign the final URL. Add every parameter before signing, and call the signed URL unchanged.

Troubleshooting