Adding the Salary Box to an application

There are three steps, and only the first two involve this site. You create a listing when you open a position, you put the box in front of candidates, and you check the ticket that comes back with each application on your own machine. There is no account to create, and the service keeps no record of your listings.

1. Create a listing

When you open a position, send the most you can pay and a short description of what the number covers. You get back a locator and a verifyKey. The locator is public and goes wherever candidates will meet the box. The verify key stays with you, stored alongside the position.

curl -X POST https://thesalarybox.com/api/listing \
  -d listingId=q7Zt0mXh3vK9wB2nR5yPa8LdUe4GsJ1cF6oVxTiN0kM \
  -d ceiling=160000 \
  --data-urlencode "basis=USD base salary per year"

{"locator":"5c1e09ab37d2f640.VVNEIGJhc2Ug….kq3Zr0…","verifyKey":"3q2-7w…"}

The ceiling should be the most you would pay an ordinary good hire for the role. If you would stretch for someone exceptional, leave the stretch out. That person will arrive marked above, and you will know from the start that hiring them means stretching.

Each listing ID needs to be effectively random. The method is to keep one organisation key and to derive each listing ID from that key and from your own posting number and revision. The Python below is a reference for the method. You can use it as it is, or automate the same derivation in whatever way makes sense for your organisation.

import base64, hashlib, hmac

def listing_id(org_key: bytes, posting: str, revision: int) -> str:
    tag = hmac.new(org_key, f"{posting}/{revision}".encode(), hashlib.sha256).digest()
    return base64.urlsafe_b64encode(tag).rstrip(b"=").decode()

listing_id(org_key, "1042", 1)   # 43 characters, and the same every time you call it

The organisation key is 32 random bytes that stay with you. With it you can produce the ID for any listing again from your own posting number, and creating the listing again with that ID returns the same verify key.

To change a ceiling, create a new listing with the next revision, and keep the old verify key for the applications already received. To close a position, stop accepting its tickets. Both of those are entries in your own records, because the service has none to update.

2. Put the box in front of candidates

There are two ways to do this. The first is for an application form you control, and the second works with any system that lets you add a link and a text question.

In your own application form

<form method="post" action="/apply">
  …
  <div data-salarybox="LOCATOR"></div>
  …
</form>
<script src="https://thesalarybox.com/embed.js" defer></script>

The script places the bordered box inside the div and adds a hidden input named salarybox_ticket, which you can rename with data-name. When the candidate enters a number in the box, the input is filled in with the ticket and submitted with the rest of the form. The div also fires an event, in case you want to react to it:

document.addEventListener("salarybox:ticket", (e) => {
  console.log(e.detail.ticket); // 43 characters; submit it with the application
});

Please leave the box as it is, without restyling or covering it, and do not put a salary field of your own beside it. Candidates are shown how to check that the box is served by the address it names, and the check is easy enough that an altered box would be noticed.

In an existing ATS, with a link and a text field

If you cannot add a script to your application form, you can still use the box. It needs two things that almost every applicant tracking system already supports, which are a link in the posting and a custom short-text question.

  1. Put this link in the job posting or in the question's help text, with your locator in place of LOCATOR:
    https://thesalarybox.com/embed?locator=LOCATOR
  2. Add a short-text question to the application, with wording along the lines of "Follow the link, enter the lowest salary you would accept, and paste the token it gives you here."

The candidate opens the link, which is a page on this site showing the same box. They enter their minimum, copy the 43-character token it returns, and paste it into your question. The answer to that question is the ticket.

3. Check the ticket

Checking a ticket takes the listing's verifyKey and returns one of three results. below means the candidate's minimum is at or below your ceiling. above means it is over, and the application is still yours to read and to decide on. invalid means the text is not a ticket for this listing.

You run the check yourself. It is a single HMAC computed with the verify key, so the service does not learn what a ticket said. The script below is the complete check, and it uses only Python's standard library.

A ticket is 16 random bytes followed by a 16-byte signature over those bytes and the one-bit answer. The service discarded the candidate's number before it issued the ticket, so the answer is all that any version of this script can recover.

check_tickets.py
"""Check Salary Box tickets on your own machine. Standard library only, and nothing is sent anywhere.

    python check_tickets.py VERIFY_KEY < tickets.csv > results.csv

Each input line is "application-id,ticket". Each output line is "application-id,result", where the result is
below (the minimum is at or below your ceiling), above, or invalid (not a ticket for this listing).

A position that has had more than one listing has more than one verify key. Give all of them:

    python check_tickets.py KEY_1 KEY_2 < tickets.csv > results.csv

A ticket reads as below or above under the key of the listing it was made for and as invalid under every other
key, so each output line becomes "application-id,result,n", where n says which key gave the result.
"""
import base64
import binascii
import hashlib
import hmac
import sys


def unb64(s: str) -> bytes:
    return base64.urlsafe_b64decode(s + "=" * (-len(s) % 4))


def check(verify_key: str, ticket: str) -> str:
    try:
        key, raw = unb64(verify_key), unb64(ticket)
    except (binascii.Error, ValueError):
        return "invalid"
    if len(key) != 32 or len(raw) != 32:
        return "invalid"
    nonce, tag = raw[:16], raw[16:]
    # The ticket is a nonce and a tag. The tag was made with your key over the nonce and the answer, so
    # the answer is whichever of the two possibilities reproduces the tag.
    for bit, result in ((1, "below"), (0, "above")):
        expected = hmac.new(key, nonce + bytes([bit]), hashlib.sha256).digest()[:16]
        if hmac.compare_digest(tag, expected):
            return result
    return "invalid"


def check_any(verify_keys: list[str], ticket: str) -> str:
    for n, verify_key in enumerate(verify_keys, start=1):
        result = check(verify_key, ticket)
        if result != "invalid":
            return result if len(verify_keys) == 1 else f"{result},{n}"
    return "invalid"


if __name__ == "__main__":
    for line in sys.stdin:
        application_id, _, ticket = line.strip().partition(",")
        if ticket:
            print(f"{application_id},{check_any(sys.argv[1:], ticket.strip())}")

You do not need to check tickets as they arrive. If the tickets live in your ATS as answers to a question, export them or read them through its API when you sit down to review, and run them through the script. It reads an application ID and a ticket from each line and writes the ID and the result, which you can load back as a tag or a column.

When a position has more than one verify key

Every listing ID has its own verify key, and a position gets a second listing whenever you change its ceiling or move it to a different operator of this protocol. Keep every verify key the position has had. A ticket reads as below or above under the key of the listing it was made for, and as invalid under every other key, so you can check a ticket against each key in turn and exactly one will answer. The script takes several keys and reports which one answered.

This is also how you would change operators. You create your new listings with the new operator, point the box or the link at it, and keep the old keys for the applications you have already received. The check never contacts an operator, so tickets from the old one stay readable for as long as you keep their keys.

If you would rather do the check inside your own application, the check function is all you need, and it is short enough to rewrite in any language. The source page has the same function in TypeScript and in Kotlin.

How it's built

The service is a function of one secret key, and that key is its only configuration. Each request is answered from the key and from what the request itself carries, which is why there are no accounts and no stored listings. The one thing the service writes is two running totals, for listings created and numbers compared. The home page shows the code that handles a candidate's number.

Running your own

Nothing about the protocol depends on this site, and we expect other operators to run it, and indeed hope that they will. The natural operators are organisations that sit between job seekers and employers and that both sides already trust. Those are job platforms and job boards, applicant tracking systems, cloud providers, and advocates for job seekers such as universities, governments and nonprofits. The box asks a job seeker to believe that their number is compared and then discarded, and that is easier to believe when the operator is an organisation they already rely on. An established operator brings that standing to the box, and more people answer honestly because of it. The operator's own market then works better, because a salary question that both sides answer honestly shows early whether a deal is possible, and that makes hiring more liquid and efficient.

The reference implementation is a single Kotlin file that uses only the JDK. It is the clearest place to read the whole protocol, and it is the one to start from if you want to operate the service. This site runs the same protocol as a TypeScript module. The two produce and accept each other's locators and tickets, and a test holds them to it. Either one runs with a single environment variable, GATE_SECRET. Both files are on the source page, which the site publishes from its own deployment, and both are released under the MIT License.

If you run your own, you will have a page that tells employers how to set it up, as this one does. Please credit the original implementation on that page to Max Reichelt, with a link to the essay that explains the idea, maxreichelt.com/essays/salary-box, and ask anyone who builds on your version to do the same. The credit belongs on the documentation, and the box that candidates see can stay free of it.

Key ID

Every locator starts with a 16-digit key ID, a public fingerprint of the secret that reveals nothing about it. GET /api/key returns the current one. If it ever changes, the secret has changed, and every new locator shows it; locators made under an old key are refused.

Stats

The service keeps a running tally of demand, which is a count of listings created and a count of numbers compared. The tally counts only requests that succeeded, so it shows us how much the service is really being used and helps us plan for load. An operator can publish the tally, in which case GET /api/stats returns it as {"listings":…,"bids":…}. When the tally is not published, that address returns 404. The totals are approximate. Checks are not counted, because they happen on your machine and the service never sees them.

Limits