If you keep screenshots as records, you'll eventually want to know that a stored copy is still the file we rendered. Add save_hashes: true to a render request and the response includes a SHA-256 hash of the render file. Store it next to the file, and you can check the file against it at any time with one command.
Why is this useful?
It's useful anywhere you keep screenshots as records and want to notice if a stored copy changes. For example:
- Compliance records: keep a copy of the policies, disclosures or terms you displayed, with a hash to check each copy against later.
- Preserving online content: articles, posts and statements get edited or deleted. A hash lets you show your stored copy hasn't changed since you saved it.
- Monitoring competitors: track how websites change over time, and compare hashes instead of downloading every render again.
How it works
Add save_hashes: true to your options. The response then includes a hashes object:
file: the SHA-256 of the exact bytes of the render file atrenderUrl. It works for every format: images, PDFs, videos, HTML and markdown.pixel(images only): the SHA-256 of the decoded image, so the same picture gives the same hash even if it's re-encoded.thumbhashis a tiny placeholder of the image.html,markdownandmetadata: the SHA-256 of each extra file you saved withsave_html,save_markdownorsave_metadata.
Use file to check a stored render. pixel is for telling whether the picture changed between two renders, and it's harder to recompute yourself, since it depends on how the image is decoded.
What it doesn't prove: the hash isn't signed, and it doesn't record when the page was captured. Anyone with a file can compute its hash, so a match shows the file is the one we returned, as recorded in the response you stored. It isn't proof to a third party, such as a court, that a page looked a certain way at a certain time. If you need that, please reach out to us.
Example
You can make a request using your favoured method. Here's an example with curl:
curl --location 'https://api.urlbox.com/v1/render/sync' \
--header 'Authorization: Bearer {{YOUR_URLBOX_SECRET_HERE}}' \
--header 'Content-Type: application/json' \
--data '{
"url": "https://theWebsiteYouWantToRender.com",
"format": "pdf",
"save_hashes": true
}'The returned JSON should look familiar, with the addition of hashes:
{
"renderUrl": "https://yourStorageLocation/yourRender.pdf",
"size": 297573,
"hashes": {
"file": "5780a1c3e9b2f07164c8d3a2b1e0f9d8c7b6a5948372615d4c3b2a1908f7e6d5"
}
}Store the response, or at least renderUrl and hashes.file, alongside the file.
Checking a file against its hash
- Download the file from
renderUrl(or take your stored copy). - Compute its SHA-256. On Linux run
sha256sum yourRender.pdf, on macOS runshasum -a 256 yourRender.pdf, and on Windows runcertutil -hashfile yourRender.pdf SHA256in Command Prompt. - Compare the result with
hashes.filefrom the response you stored.
If they match, the file you have is the one we returned. If a single byte has changed, the hash will be completely different.
Here's what that looks like:
$ sha256sum yourRender.pdf
5780a1c3e9b2f07164c8d3a2b1e0f9d8c7b6a5948372615d4c3b2a1908f7e6d5 yourRender.pdfIf you use the certify option
certify was our first version of this, and it still works for existing integrations, though we now recommend save_hashes. With certify: true, the response includes:
- A
timestampof when the render was taken, from our servers' clock. - A
certifiedHash: the SHA-256 of"{fileHash}.{timestamp}.{hashedOptions}", wherefileHashis the SHA-256 of the render file. - The
hashedOptionsused in the hash. These may differ slightly from the options you sent, because some options add others. For example,use_s3=trueadds ans3_presigned_url, which expires shortly after the render.
certify needs the Ultra plan or above. It returns no hash for video formats, it can't be used with html instead of url, and it refuses options that change the page a lot or could hold sensitive data, such as js, css, cookie and proxy (use_s3 is allowed).
The same limits apply as above: the hash isn't signed, and the timestamp is our own clock, so certifiedHash shows the file still matches the response you stored, not when the page was captured.
To check a file against a certifiedHash, save the script below as verify.sh, run chmod +x verify.sh, make sure you have jq, then run ./verify.sh /path/to/the/downloaded/file.pdf. Paste the JSON response when prompted and press Ctrl+D twice.
#!/bin/bash
# Check that we passed in the downloaded file path
if [[ $# -lt 1 ]]; then
echo "Error: Missing local file path."
echo "Usage: ./verify.sh <localFilePath>"
exit 1
fi
FILE_PATH="$1"
# Ensure the file exists
if [[ ! -f "$FILE_PATH" ]]; then
echo "Error: File '$FILE_PATH' not found."
exit 1
fi
# Prompt to paste render response JSON
echo "Paste JSON payload and press Ctrl+D twice when done:"
JSON_INPUT=$(jq -nR '[inputs] | join("\n")' | jq -r '. | fromjson' 2>/dev/null)
# Validate the JSON
if [[ -z "$JSON_INPUT" || $(echo "$JSON_INPUT" | jq empty 2>&1) ]]; then
echo "Error: Invalid JSON provided."
exit 1
fi
# Extract values from the JSON
RENDER_TIMESTAMP=$(echo "$JSON_INPUT" | jq -r '.timestamp')
CERTIFIED_HASH=$(echo "$JSON_INPUT" | jq -r '.certifiedHash')
HASHED_OPTIONS_JSON=$(echo "$JSON_INPUT" | jq -cS '.hashedOptions')
# Compute SHA-256 hash of the file
BUFFER_HASH=$(shasum -a 256 "$FILE_PATH" | awk '{print $1}')
echo
echo "FILE: $FILE_PATH"
echo "BUFFER_HASH: $BUFFER_HASH"
echo "OPTIONS: $HASHED_OPTIONS_JSON"
echo "TIMESTAMP: $RENDER_TIMESTAMP"
echo
# Compute the final hash to compare against the certified hash
FINAL_HASH=$(echo -n "$BUFFER_HASH.$RENDER_TIMESTAMP.$HASHED_OPTIONS_JSON" | shasum -a 256 | awk '{print $1}')
# Compare hashes
MATCH_RESULT="false"
if [[ "$FINAL_HASH" == "$CERTIFIED_HASH" ]]; then
MATCH_RESULT="true"
fi
# Output results in JSON format
jq -n \
--arg computedHash "$FINAL_HASH" \
--arg certifiedHash "$CERTIFIED_HASH" \
--arg match "$MATCH_RESULT" \
'{computedHash: $computedHash, certifiedHash: $certifiedHash, match: $match}'
If match is "true", the file is the one we rendered with those options, as recorded in the response you stored.
If you're struggling to get started, or to check your renders, please do reach out to us.
