Repository navigation
fix(frontend): resolve high CodeQL xss-through-dom and clear-text storage alerts #3648
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4cf4301
fix(frontend): stop storing session email in web storage (CodeQL js/c…
PetrefiedThunder d49a00a
fix(frontend): drop in-memory session email and assert email is never…
PetrefiedThunder 90718e2
fix(auth): redact email from all cached session profiles
PetrefiedThunder 2a6bfcc
Merge remote-tracking branch 'origin/main' into openclaw/codex-3648-s…
PetrefiedThunder f65250a
chore: merge main proof-page cleanup for copy gate
PetrefiedThunder 48d5f9a
chore: merge origin/main into muse/codeql-frontend-high
PetrefiedThunder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { beforeEach, describe, expect, it } from 'vitest'; | ||
|
|
||
| import { seedClientSessionUser, serializeClientSessionUser } from '@/lib/client-session-profile'; | ||
|
|
||
| function collectEmailValues(value: unknown, acc: unknown[] = []): unknown[] { | ||
| if (Array.isArray(value)) { | ||
| for (const item of value) collectEmailValues(item, acc); | ||
| } else if (value !== null && typeof value === 'object') { | ||
| for (const [key, entry] of Object.entries(value as Record<string, unknown>)) { | ||
| if (key.toLowerCase() === 'email') acc.push(entry); | ||
| collectEmailValues(entry, acc); | ||
| } | ||
| } | ||
| return acc; | ||
| } | ||
|
|
||
| describe('seedClientSessionUser', () => { | ||
| beforeEach(() => { | ||
| window.localStorage.clear(); | ||
| window.sessionStorage.clear(); | ||
| }); | ||
|
|
||
| it('stores a non-sensitive placeholder profile without the email', () => { | ||
| const email = `${crypto.randomUUID()}@example.test`; | ||
|
|
||
| seedClientSessionUser(email); | ||
|
|
||
| const stored = window.localStorage.getItem('regengine_user'); | ||
| expect(stored).not.toBeNull(); | ||
| expect(stored as string).not.toContain(email); | ||
| expect(stored as string).not.toContain(email.split('@')[0]); | ||
| expect(window.sessionStorage.getItem('regengine_user')).toBeNull(); | ||
|
|
||
| const parsed = JSON.parse(stored as string) as Record<string, unknown>; | ||
| expect(parsed).toMatchObject({ | ||
| id: 'email-session', | ||
| email: '', | ||
| is_sysadmin: false, | ||
| status: 'active', | ||
| role_name: 'member', | ||
| permissions: [], | ||
| }); | ||
|
|
||
| const emailValues = collectEmailValues(parsed); | ||
| expect(emailValues.length).toBeGreaterThan(0); | ||
| for (const value of emailValues) { | ||
| expect(value).toBe(''); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe('serializeClientSessionUser', () => { | ||
| it('omits email without mutating the authenticated profile or its permissions', () => { | ||
| const user = { | ||
| id: crypto.randomUUID(), | ||
| email: `${crypto.randomUUID()}@example.test`, | ||
| is_sysadmin: false, | ||
| status: 'active', | ||
| role_name: 'member', | ||
| permissions: ['reports.read'], | ||
| }; | ||
| const original = structuredClone(user); | ||
|
|
||
| const stored = serializeClientSessionUser(user); | ||
|
|
||
| expect(JSON.parse(stored)).toEqual({ ...original, email: '' }); | ||
| expect(stored).not.toContain(original.email); | ||
| expect(stored).not.toContain(original.email.split('@')[0]); | ||
| expect(user).toEqual(original); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,26 @@ | ||
| import type { User } from '@/types/api'; | ||
|
|
||
| // Keep the authenticated profile intact in memory; cache no email in web storage. | ||
| export function serializeClientSessionUser(user: User | null): string { | ||
| return JSON.stringify(user ? { ...user, email: '' } : null); | ||
| } | ||
|
|
||
| // Seeds a non-sensitive placeholder profile only: the email argument is | ||
| // intentionally never persisted to web storage nor held in module state | ||
| // (CodeQL js/clear-text-storage-of-sensitive-data). The real session fetch | ||
| // provides the authenticated user in memory. | ||
| export function seedClientSessionUser(email: string): void { | ||
| void email; | ||
| if (typeof window === 'undefined') return; | ||
|
|
||
| const user: User = { | ||
| id: 'email-session', | ||
| email, | ||
| email: '', | ||
|
PetrefiedThunder marked this conversation as resolved.
Resolved
|
||
| is_sysadmin: false, | ||
| status: 'active', | ||
| role_name: 'member', | ||
| permissions: [], | ||
| }; | ||
|
|
||
| window.localStorage.setItem('regengine_user', JSON.stringify(user)); | ||
| window.localStorage.setItem('regengine_user', serializeClientSessionUser(user)); | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.