GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(Auth): retain expiration in FileSystemCacheItemPool and return null in CacheTrait by cy-yun · Pull Request #9687 · googleapis/google-cloud-php

Conversation

@cy-yun

@cy-yun cy-yun commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #9669

Problem

In FileSystemCacheItemPool::save(), the pool called serialize($item->get()). This discarded all expiration metadata and cache item status on save. When getItem() was subsequently called, it instantiated a new TypedItem($key) and called $item->set(...), setting $isHit to true and clearing any expiration. As a result, items never expired in the file cache, leading to stale authentication tokens being reused indefinitely. Additionally, in CacheTrait::getCachedValue(), when $cacheItem->isHit() was false, the method implicitly fell off without an explicit return statement.

Solution

  1. FileSystemCacheItemPool::save(): Directly serialize $item (serialize($item)) so expiration and cache metadata are retained.
  2. FileSystemCacheItemPool::getItem(): Unserialize the data; if it is an instance of CacheItemInterface, return it directly. For backward compatibility with legacy cache files on disk containing raw serialized values, fallback to creating a new TypedItem($key) and setting the value.
  3. CacheTrait::getCachedValue(): Add an explicit return null; at the end of the method when cache items are missed or expired.

Verification

  • Added testSaveAndGetExpiredItem in FileSystemCacheItemPoolTest verifying that expired cache items return false for isHit() and null for get().
  • Added testGetItemLegacyCacheFile in FileSystemCacheItemPoolTest verifying backward compatibility with legacy serialized cache files.
  • Added testFailsPullFromCacheWhenItemIsNotHit in CacheTraitTest verifying explicit null return on cache miss.
  • Ran test suite: HOME=/tmp vendor/bin/phpunit Auth/tests/Cache/FileSystemCacheItemPoolTest.php (passed).
  • Ran test suite: HOME=/tmp vendor/bin/phpunit Auth/tests/CacheTraitTest.php (passed).
  • Ran CS Fixer: vendor/bin/php-tools cs-fixer googleapis/google-cloud-php --ref HEAD (0 files that can be fixed).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cy-yun
fix(Auth): retain expiration in FileSystemCacheItemPool and return nu…
fd8ad9e
…ll in CacheTrait (#9669)
@cy-yun
cy-yun requested a review from a team as a code owner September 14, 2026 20:56
@cy-yun cy-yun assigned Hectorhammett Sep 14, 2026
bshaffer
bshaffer reviewed Sep 21, 2026
View reviewed changes

@bshaffer bshaffer left a comment

Copy link
Copy Markdown
Contributor

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.

Wow, this is a huge bug. Thank you for finding it (@indreka) and fixing it (@cy-yun)!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Auth/tests/CacheTraitTest.php
$this->assertEquals($expectedValue, $cachedValue);
}

public function testFailsPullFromCacheWhenItemIsNotHit()

@bshaffer bshaffer Sep 21, 2026

Copy link
Copy Markdown
Contributor

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.

FYI, this test passes on main, so Im not quite sure what the intent is, but the more tests the better, so this seems fine to add.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Auth/tests/Cache/FileSystemCacheItemPoolTest.php
Comment on lines +70 to +91
public function testSaveAndGetExpiredItem()
{
$item = $this->getNewItem();
$item->expiresAt(new DateTime('yesterday'));
$this->pool->save($item);
$retrievedItem = $this->pool->getItem($item->getKey());

$this->assertFalse($retrievedItem->isHit());
$this->assertNull($retrievedItem->get());
}

public function testGetItemLegacyCacheFile()
{
$key = 'LegacyItem';
$itemPath = $this->cachePath . '/' . $key;
file_put_contents($itemPath, serialize('legacyValue'));

$retrievedItem = $this->pool->getItem($key);

$this->assertTrue($retrievedItem->isHit());
$this->assertEquals('legacyValue', $retrievedItem->get());
}

@bshaffer bshaffer Sep 21, 2026

Copy link
Copy Markdown
Contributor

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.

these tests are great!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
bshaffer
bshaffer approved these changes Sep 21, 2026
View reviewed changes
@bshaffer
bshaffer merged commit 47ff41c into main Sep 21, 2026
39 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bshaffer
bshaffer deleted the fix/auth-filesystem-cache-expiration branch September 21, 2026 17:28
@release-please release-please Bot mentioned this pull request Sep 21, 2026
chore(main): release 0.346.0 #9692
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bshaffer bshaffer bshaffer approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@Hectorhammett Hectorhammett

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Auth] FileSystemCacheItemPool implementation is broken, it loses expiration information and causes stale auth token usage

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@cy-yun @bshaffer @Hectorhammett
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.