Skip to content

[HttpFoundation] Add UriSigner::verify() that throws named exceptions #60102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2025

Conversation

kbond
Copy link
Member

@kbond kbond commented Mar 31, 2025

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues n/a
License MIT

This adds UriSigner::verify(): Similar to check() but throws UnSignedUriException, UnverifiedSignedUriException or ExpiredSignedUriException if invalid (no return if valid).

Usage example:

// Verifying a Signed Uri
try {
    $uriSigner->verify($uri);
} catch (UnSignedUriException $e) {
    // the uri either not signed
    $e->uri; // the uri value
} catch (UnverifiedSignedUriException $e) {
    // the the signature is invalid
    $e->uri; // the uri value
} catch (ExpiredSignedUriException $e) {
    // the signature is valid but it's expired
    $e->uri; // the uri value
    $e->expiredAt; // \DateTimeImmutable
}

TODO

  • Changelog
  • Tests

@kbond kbond added the RFC RFC = Request For Comments (proposals about features that you want to be discussed) label Mar 31, 2025
@carsonbot carsonbot changed the title [HttpFoundation] Add UriSigner::signAndWrap(): SignedUri and UriSigner::verify(): SignedUri Add UriSigner::signAndWrap(): SignedUri and UriSigner::verify(): SignedUri Mar 31, 2025
@carsonbot carsonbot added this to the 7.3 milestone Mar 31, 2025
@carsonbot carsonbot changed the title Add UriSigner::signAndWrap(): SignedUri and UriSigner::verify(): SignedUri [HttpFoundation] Add UriSigner::signAndWrap(): SignedUri and UriSigner::verify(): SignedUri Mar 31, 2025
@OskarStark OskarStark changed the title [HttpFoundation] Add UriSigner::signAndWrap(): SignedUri and UriSigner::verify(): SignedUri [HttpFoundation] Add UriSigner::signAndWrap() and UriSigner::verify() Apr 1, 2025
@kbond
Copy link
Member Author

kbond commented Apr 2, 2025

I'm not a huge fan of signAndWrap() and the SignedUri VO. I'd be ok dropping these and just keeping verify() + named exceptions.

@kbond kbond force-pushed the uri-signer-ensure-valid branch 2 times, most recently from ee8c09d to a627d43 Compare April 2, 2025 19:35
@kbond kbond changed the title [HttpFoundation] Add UriSigner::signAndWrap() and UriSigner::verify() [HttpFoundation] Add UriSigner::verify() that throws named exceptions Apr 2, 2025
@kbond
Copy link
Member Author

kbond commented Apr 2, 2025

I've updated this PR to just add SignedUri::verify().

@kbond kbond removed the RFC RFC = Request For Comments (proposals about features that you want to be discussed) label Apr 2, 2025
@nicolas-grekas
Copy link
Member

(rebase needed)

@kbond kbond force-pushed the uri-signer-ensure-valid branch from 493f298 to 60b8ba7 Compare April 18, 2025 16:01
@nicolas-grekas nicolas-grekas force-pushed the uri-signer-ensure-valid branch from ce0feb3 to ac4de2c Compare April 18, 2025 21:02
@nicolas-grekas
Copy link
Member

Thank you @kbond.

@nicolas-grekas nicolas-grekas merged commit eb71515 into symfony:7.3 Apr 18, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants