PayloadSigner
in package
Payload signer class - HMAC-signs/verifies the serialized bytes every storage adapter writes, closing the unserialize() object-injection gap for anyone who can write to the underlying storage directly (a compromised Redis instance, SQL injection elsewhere in the host app, a writable queue directory). Static-only, mirroring Laravel\SerializableClosure::setSecretKey()'s own static-global shape - a familiar idiom already present in this project's dependency tree.
When no key is configured (the default), sign()/verify() are exact pass-throughs - zero behavior change from every adapter's current, unsigned serialize()/unserialize() round-trip. Once setKey() is called (recommended once, at application bootstrap, before any queue/worker operation), sign() prepends a raw 32-byte HMAC-SHA256 and verify() checks it with hash_equals() before returning the payload bytes - a failed check means the caller must never pass those bytes to unserialize() at all.
Tags
Table of Contents
Properties
- $key : string|null
- Signing key. Null (the default) disables signing entirely - sign() and verify() both become pass-throughs.
Methods
- hasKey() : bool
- Whether a signing key is currently configured
- setKey() : void
- Set the signing key. Pass null to disable signing again.
- sign() : string
- Sign a payload. Pass-through when no key is configured.
- verify() : string|false
- Verify a signed payload, returning the original payload bytes on success. Pass-through when no key is configured. Returns false on any verification failure (missing/truncated signature, tampered signature, tampered payload, or a payload signed with a different key) - callers must never unserialize() the input when this returns false.
Properties
$key
Signing key. Null (the default) disables signing entirely - sign() and verify() both become pass-throughs.
protected
static string|null
$key
= null
Methods
hasKey()
Whether a signing key is currently configured
public
static hasKey() : bool
Return values
boolsetKey()
Set the signing key. Pass null to disable signing again.
public
static setKey(string|null $key) : void
Parameters
- $key : string|null
sign()
Sign a payload. Pass-through when no key is configured.
public
static sign(string $payload) : string
Parameters
- $payload : string
Return values
stringverify()
Verify a signed payload, returning the original payload bytes on success. Pass-through when no key is configured. Returns false on any verification failure (missing/truncated signature, tampered signature, tampered payload, or a payload signed with a different key) - callers must never unserialize() the input when this returns false.
public
static verify(string $signed) : string|false
Parameters
- $signed : string