# What Stripe webhook signing secrets the library redacts, and what it leaves
# alone.
#
# Webhook signing secret is Stripe's own name for this value, and it is a
# pattern of its own because no term of Stripe's covers it and the API keys
# together: Stripe's table of key types has four rows, this is in none of them,
# and it is issued per endpoint rather than per account. What those rows are is
# what the Stripe files beside this one hold.
#
# Every secret here is built from the ordered run 0123456789abcdef, which no
# real credential is, written out until it is the thirty-two characters the
# pattern holds a body to. That count is a floor and not an abbreviation: a body
# shortened for readability would leave a case holding no secret at all. One
# case carries twice the floor, which is the width of the placeholder Stripe
# writes into its own example environment file, to say that the floor is not a
# count.
#
# The case redacted under the over-match heading is no secret and nobody issued
# it. What it holds is a word somebody wrote where a secret goes, long enough to
# reach the floor unbroken, which is the whole of what the pattern asks for.

patterns: stripe-webhook-signing-secret

# The one prefix Stripe has issued a signing secret with. There is a single kind
# of string here rather than a table of them: a secret says neither which
# endpoint it signs for nor whether that endpoint is a sandbox one, so a secret
# rolled from the endpoint's page, one created with the API and one the CLI
# prints for a forwarding session are all the same shape, and the cases below
# are that shape in the places a secret is written.

case:     a secret in an environment assignment
in:       STRIPE_WEBHOOK_SECRET=whsec_0123456789abcdef0123456789abcdef
out:      STRIPE_WEBHOOK_SECRET=«stripe-webhook-signing-secret»

case:     a secret in the line the stripe cli announces a session with
in:       > Ready! Your webhook signing secret is whsec_0123456789abcdef0123456789abcdef (^C to quit)
out:      > Ready! Your webhook signing secret is «stripe-webhook-signing-secret» (^C to quit)

case:     a secret in the field a webhook endpoint carries it in
in:       {"object":"webhook_endpoint","secret":"whsec_0123456789abcdef0123456789abcdef"}
out:      {"object":"webhook_endpoint","secret":"«stripe-webhook-signing-secret»"}

case:     a secret in the field an event destination carries it in
in:       {"webhook_endpoint":{"signing_secret":"whsec_0123456789abcdef0123456789abcdef"}}
out:      {"webhook_endpoint":{"signing_secret":"«stripe-webhook-signing-secret»"}}

case:     a secret written into a source file
in:       const endpointSecret = 'whsec_0123456789abcdef0123456789abcdef';
out:      const endpointSecret = '«stripe-webhook-signing-secret»';

# The alphabet the thirty-two characters are written in. It is base62 — the
# letters of both cases and the digits — which is what both of the secrets
# Stripe has printed are written in. The two characters base64url adds are not
# admitted, and neither are the two standard base64 adds nor the character it
# pads with, which is the whole of what the scrubber in Stripe's own CLI reads
# behind this prefix. Any of the five ends a body where it stands, and where a
# whole body stands in front of one the redaction stops short of it.

case:     a body written in capitals
in:       whsec_0123456789ABCDEF0123456789ABCDEF
out:      «stripe-webhook-signing-secret»

case:     a body carrying a hyphen
in:       whsec_0123456789abcdef-0123456789abcdef
out:      whsec_0123456789abcdef-0123456789abcdef

case:     a body carrying an underscore
in:       whsec_0123456789abcdef_0123456789abcdef
out:      whsec_0123456789abcdef_0123456789abcdef

case:     a body carrying a plus
in:       whsec_0123456789abcdef+0123456789abcdef
out:      whsec_0123456789abcdef+0123456789abcdef

case:     a body carrying a slash
in:       whsec_0123456789abcdef/0123456789abcdef
out:      whsec_0123456789abcdef/0123456789abcdef

case:     a body carrying the character standard base64 pads with
in:       whsec_0123456789abcdef=0123456789abcdef
out:      whsec_0123456789abcdef=0123456789abcdef

case:     that character written behind a whole body
in:       whsec_0123456789abcdef0123456789abcdef==
out:      «stripe-webhook-signing-secret»==

# The lengths either side of thirty-two. Stripe states no length for a secret;
# what it has printed is two of them, both thirty-two characters behind the
# prefix, and a placeholder of sixty-four in its own webhook signing example.
# The count is read as a floor for that reason: thirty-one characters are not a
# secret, and thirty-three are one secret to the end of its run rather than a
# secret and a character left over. What the floor costs is the secret cut
# short: a line cut to a column limit partway through one leaves a body too
# short to be a body, and every random character written in front of the cut
# comes through in the clear. That is what the cases below holding no secret
# are.

case:     a body of thirty-two characters is a secret
in:       whsec_0123456789abcdef0123456789abcdef
out:      «stripe-webhook-signing-secret»

case:     a body of thirty-one characters is not
in:       STRIPE_WEBHOOK_SECRET=whsec_0123456789abcdef0123456789abcde
out:      STRIPE_WEBHOOK_SECRET=whsec_0123456789abcdef0123456789abcde

case:     a secret cut off at its prefix
in:       STRIPE_WEBHOOK_SECRET=whsec_
out:      STRIPE_WEBHOOK_SECRET=whsec_

case:     an alphabet run longer than the floor is a secret to the end of it
in:       whsec_0123456789abcdef0123456789abcdef0
out:      «stripe-webhook-signing-secret»

case:     the width of the placeholder Stripe writes into its own example
in:       whsec_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
out:      «stripe-webhook-signing-secret»

# What a secret may be written against. The prefix is the whole of the anchor
# and there is no boundary on either side of it, so a secret keeps its span
# whatever character stands in front of it — which is where this pattern parts
# from the Stripe API key patterns beside it. Their key types can close a word
# and six characters ending in whsec cannot, so there is no such text for their
# demand to turn away here; what it would turn away is the secrets written
# together and the prefix inside a base64url run, both of which have cases of
# their own here, and the pattern's own file weighs that trade. Behind the
# secret the redaction reaches to the end of the run, so a letter or a digit
# written straight after one is redacted with it, while a hyphen, an underscore,
# a slash, a space or a quote ends the run and stays.

case:     a secret after an underscore
in:       STRIPE_WEBHOOK_SECRET_whsec_0123456789abcdef0123456789abcdef
out:      STRIPE_WEBHOOK_SECRET_«stripe-webhook-signing-secret»

case:     a secret after a letter
in:       xwhsec_0123456789abcdef0123456789abcdef
out:      x«stripe-webhook-signing-secret»

case:     a secret after a digit
in:       1whsec_0123456789abcdef0123456789abcdef
out:      1«stripe-webhook-signing-secret»

case:     a word written against a secret
in:       whsec_0123456789abcdef0123456789abcdefsuffix
out:      «stripe-webhook-signing-secret»

case:     a hyphenated word written against a secret
in:       whsec_0123456789abcdef0123456789abcdef-suffix
out:      «stripe-webhook-signing-secret»-suffix

case:     an underscored word written against a secret
in:       whsec_0123456789abcdef0123456789abcdef_suffix
out:      «stripe-webhook-signing-secret»_suffix

case:     a path written against a secret
in:       whsec_0123456789abcdef0123456789abcdef/webhook
out:      «stripe-webhook-signing-secret»/webhook

case:     a secret at the end of a sentence
in:       the secret is whsec_0123456789abcdef0123456789abcdef.
out:      the secret is «stripe-webhook-signing-secret».

case:     a secret inside quotes
in:       export STRIPE_WEBHOOK_SECRET="whsec_0123456789abcdef0123456789abcdef"
out:      export STRIPE_WEBHOOK_SECRET="«stripe-webhook-signing-secret»"

# Two secrets written together. The five letters the prefix opens with belong to
# the alphabet a body is written in, so the first two cases below are each one
# redaction rather than two, for reasons that are not the same. In the first a
# body closes with whsec and the underscore of the next secret stands directly
# behind it, so the second secret begins five characters before the first one
# ends. In the second the two are simply written against each other, and the
# first secret's run reads over the letters of the second's prefix before an
# underscore ends it. Either way the spans overlap and are redacted as one. Put
# a byte the alphabet does not hold between them, as the last case does, and
# they are separate values and both go.

case:     a secret beginning inside the secret before it
in:       whsec_0123456789abcdef0123456789awhsec_0123456789abcdef0123456789abcdef
out:      «stripe-webhook-signing-secret»

case:     two secrets with nothing between them
in:       whsec_0123456789abcdef0123456789abcdefwhsec_0123456789ABCDEF0123456789ABCDEF
out:      «stripe-webhook-signing-secret»

case:     two secrets separated by a space
in:       whsec_0123456789abcdef0123456789abcdef whsec_0123456789ABCDEF0123456789ABCDEF
out:      «stripe-webhook-signing-secret» «stripe-webhook-signing-secret»

# What this pattern redacts that nobody issued: the placeholder that reaches the
# floor. The prefix is followed by a word somebody wrote far more often than by
# a secret, and where that word runs thirty-two characters unbroken it is a
# secret's format exactly — Stripe writes nothing into a secret a written-out
# word could not hold — so nothing is left in the text to read the two apart by.
# Declining it would mean declining every secret Stripe wrote in the letters
# alone. The cases after it are where the floor and the alphabet hold instead:
# a placeholder shorter than the floor is turned away, as the one Stripe writes
# into its own CLI reference is, and one written in snake_case ends at its next
# underscore however long the whole of it runs.

case:     a placeholder of thirty-two unbroken characters
in:       STRIPE_WEBHOOK_SECRET=whsec_replacethiswithyoursigningsecret
out:      STRIPE_WEBHOOK_SECRET=«stripe-webhook-signing-secret»

case:     a placeholder short of the floor
in:       STRIPE_WEBHOOK_SECRET=whsec_yoursecret
out:      STRIPE_WEBHOOK_SECRET=whsec_yoursecret

case:     the placeholder Stripe writes into its own cli reference
in:       STRIPE_WEBHOOK_SECRET=whsec_abcdefg1234567
out:      STRIPE_WEBHOOK_SECRET=whsec_abcdefg1234567

case:     a placeholder written in snake_case
in:       STRIPE_WEBHOOK_SECRET=whsec_replace_this_with_your_signing_secret
out:      STRIPE_WEBHOOK_SECRET=whsec_replace_this_with_your_signing_secret

# The prefix written inside a run nobody meant as one. Standard base64 carries
# no underscore, so a certificate, a PEM body or an embedded image holds no
# prefix to be found at however long it runs, and only a base64url encoding can
# hold one — there six characters of an alphabet of sixty-four stand where the
# prefix stands about once in seventy thousand million characters. Where
# thirty-two base62 characters follow, the run from the prefix to the end of
# them is redacted whether or not Stripe issued it, because such a run is a
# secret's format exactly. What is taken is a stretch of a value that was
# already opaque to a reader.

case:     the prefix inside a longer run of base64url
in:       payload=zzzzwhsec_0123456789abcdef0123456789abcdefzzzz
out:      payload=zzzz«stripe-webhook-signing-secret»

case:     the prefix where a signature stands
in:       eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhYmMifQ.zzzzwhsec_0123456789abcdef0123456789abcdefzzzz
out:      eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhYmMifQ.zzzz«stripe-webhook-signing-secret»

# And what this pattern leaves alone. The first three are the prefix, read in
# the case Stripe writes it, with the underscore Stripe closes it with, and in
# every one of its letters. The two after them are the alphabet and the anchor:
# a body a space has broken, and a run of the right length with no prefix in
# front of it. The two after those hold no underscore where the prefix wants
# one, so they hold no position to be found at however long they run. The last
# is a credential of the same vendor that another pattern reads, and it is here
# to say that this one does not.

case:     an uppercase prefix
in:       WHSEC_0123456789abcdef0123456789abcdef
out:      WHSEC_0123456789abcdef0123456789abcdef

case:     a hyphen where the prefix carries an underscore
in:       whsec-0123456789abcdef0123456789abcdef
out:      whsec-0123456789abcdef0123456789abcdef

case:     one character of the prefix wrong
in:       whsex_0123456789abcdef0123456789abcdef
out:      whsex_0123456789abcdef0123456789abcdef

case:     a body broken by a space
in:       whsec_0123456789abcdef 0123456789abcdef
out:      whsec_0123456789abcdef 0123456789abcdef

case:     a run of the right length opening with no prefix
in:       0123456789abcdef0123456789abcdef
out:      0123456789abcdef0123456789abcdef

case:     a hexadecimal digest
in:       sha256=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
out:      sha256=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef

case:     prose
in:       there is no credential in this sentence
out:      there is no credential in this sentence

case:     a stripe secret key, which another pattern reads
in:       sk_live_0123456789abcdef01234567
out:      sk_live_0123456789abcdef01234567
