Skip to content

adding guard for local storage key prefix#141

Merged
djanhjo merged 5 commits intodevelopfrom
inapp-14355
Apr 6, 2026
Merged

adding guard for local storage key prefix#141
djanhjo merged 5 commits intodevelopfrom
inapp-14355

Conversation

@djanhjo
Copy link
Copy Markdown
Contributor

@djanhjo djanhjo commented Apr 6, 2026

Note

Medium Risk
Changes local/session storage cleanup behavior so expiry logic no longer runs for non-gist. keys, which could leave stale entries if any callers rely on expiry for other prefixes. Scope is small but affects persistence/cleanup semantics.

Overview
Adds a gist. prefix guard to local/session storage expiry handling so only gist.-namespaced keys are checked and auto-removed during clearExpiredFromLocalStore() and getKeyFromLocalStore().

Updates tests to consistently use gist.* keys and adds coverage ensuring non-gist. keys can still be read without being deleted.

Reviewed by Cursor Bugbot for commit f257b03. Bugbot is set up for automated code reviews on this repo. Configure here.

@djanhjo djanhjo requested a review from a team as a code owner April 6, 2026 14:27
Copy link
Copy Markdown
Contributor

@mvanderlinde mvanderlinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code change itself looks straightforward, but I did add a question about optional chaining. Approving with the caveat that tests are fixed (looks like a bunch are failing, I assume because the test key names don't start with gist.)

Comment thread src/utilities/local-storage.ts Outdated

function checkKeyForExpiry(key: string | null): unknown | null {
if (!key) return null;
if (!key || !key.startsWith('gist.')) return null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: Could this be simplified to...

Suggested change
if (!key || !key.startsWith('gist.')) return null;
if (!key?.startsWith('gist.')) return null;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Or my preference if it's a single condition, key?.startsWith('gist.') !== true.

Comment thread src/utilities/local-storage.ts Outdated
if (now.getTime() > expiryTime.getTime()) {
clearKeyFromLocalStore(key);
return null;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guard for non-gist keys doesn't prevent returning values

High Severity

The gist. prefix guard in checkKeyForExpiry only wraps the expiry-checking logic (lines 76–97), but return item.value on line 99 sits outside the guard. For any key that doesn't start with 'gist.' but exists in storage with an expiry (which is always the case since setKeyToLocalStore defaults to a 365-day expiry), the function skips the if block and falls through to return the stored value. The guard needs to return null early for non-gist. keys — e.g., if (!key.startsWith('gist.')) return null — instead of only wrapping the expiry logic.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit eb7b7df. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an active choice to retain preexisting behavior. Will have a followup PR to explicitly restrict local storage functionality across various operations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #142.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 766bb8e. Configure here.

Comment thread src/utilities/local-storage.ts
@djanhjo djanhjo merged commit 5ec1c4a into develop Apr 6, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants