-
Notifications
You must be signed in to change notification settings - Fork 0
Unpushed commits (local main ahead of origin/main) #32
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| use DateTimeImmutable; | ||||||||||||||||||||||||||
| use Illuminate\Support\Carbon; | ||||||||||||||||||||||||||
| use JsonException; | ||||||||||||||||||||||||||
| use Saloon\Contracts\OAuthAuthenticator; | ||||||||||||||||||||||||||
| use Saloon\Http\PendingRequest; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -88,18 +89,52 @@ | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * Serialize the access token. | ||||||||||||||||||||||||||
| * Encode for cache storage (JSON). Replaces PHP serialize, which is unsafe and unsupported with Saloon v4+. | ||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||
| * @throws JsonException | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| public function serialize(): string | ||||||||||||||||||||||||||
| public function encodeForCache(): string | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| return serialize($this); | ||||||||||||||||||||||||||
| return json_encode([ | ||||||||||||||||||||||||||
| 'accessToken' => $this->accessToken, | ||||||||||||||||||||||||||
| 'refreshToken' => $this->refreshToken, | ||||||||||||||||||||||||||
| 'expiresAt' => $this->expiresAt?->format(DATE_ATOM), | ||||||||||||||||||||||||||
| ], JSON_THROW_ON_ERROR); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * Unserialize the access token. | ||||||||||||||||||||||||||
| * Restore from cache. Supports JSON (current) and legacy PHP-serialized payloads for one-time migration. | ||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||
| * @throws JsonException | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| public static function unserialize(string $string): static | ||||||||||||||||||||||||||
| public static function decodeFromCache(string $payload): static | ||||||||||||||||||||||||||
|
Comment on lines
+92
to
+110
|
||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| return unserialize($string, ['allowed_classes' => true]); | ||||||||||||||||||||||||||
| $trimmed = ltrim($payload); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if ($trimmed !== '' && $trimmed[0] === '{') { | ||||||||||||||||||||||||||
| $data = json_decode($payload, true, 512, JSON_THROW_ON_ERROR); | ||||||||||||||||||||||||||
| $expiresAt = isset($data['expiresAt']) && is_string($data['expiresAt']) && $data['expiresAt'] !== '' | ||||||||||||||||||||||||||
| ? new DateTimeImmutable($data['expiresAt']) | ||||||||||||||||||||||||||
| : null; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
+116
to
+119
|
||||||||||||||||||||||||||
| $expiresAt = isset($data['expiresAt']) && is_string($data['expiresAt']) && $data['expiresAt'] !== '' | |
| ? new DateTimeImmutable($data['expiresAt']) | |
| : null; | |
| $expiresAt = null; | |
| if (isset($data['expiresAt']) && is_string($data['expiresAt']) && $data['expiresAt'] !== '') { | |
| try { | |
| $expiresAt = new DateTimeImmutable($data['expiresAt']); | |
| } catch (\Exception $e) { | |
| throw new JsonException('Invalid expiresAt value in cached Instagram authenticator payload.', 0, $e); | |
| } | |
| } |
Check failure on line 120 in src/Authenticator/InstagramAuthenticator.php
GitHub Actions / phpstan
Unsafe usage of new static().
Copilot
AI
Mar 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the JSON branch, $data['accessToken'] is used without checking it exists/is a string. A corrupted/partial cache entry will trigger notices/type errors rather than a controlled exception. Add explicit validation for required keys/types (and throw an InvalidArgumentException if invalid) before constructing the authenticator.
Copilot
AI
Mar 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new cache encoding/decoding logic (JSON + legacy PHP-serialized migration path) isn't covered by tests. Add tests for encodeForCache/decodeFromCache round-tripping, and for successfully reading a legacy serialized payload, to prevent regressions during the Saloon v4 migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decodeFromCachecan now throw (e.g.,JsonException/InvalidArgumentException) when the cached payload is corrupted. Consider catching decode failures here, clearing the cache key (similar to theempty($serialized)branch), and throwing the same "No authenticator found" exception to avoid hard failures from a single bad cache value.