fix: address security and UX issues in request filters#488
fix: address security and UX issues in request filters#488ding113 merged 3 commits intoding113:devfrom
Conversation
Address 4 bugs identified in code review (Codex AI):
1. CRITICAL: Prevent provider API keys leak to browser
- Only pass {id, name} to client component FilterTable
- Remove Provider type import, use inline type
- Files: page.tsx, filter-table.tsx
2. HIGH: Add ReDoS validation for pre-compiled regex
- Check safeRegex() before compiling in reload()
- Check safeRegex() in setFiltersForTest()
- Skip unsafe patterns with warning log
- File: request-filter-engine.ts
3. MEDIUM: Fix double-toggle in provider multi-select
- Remove duplicate onCheckedChange handler
- Keep only onSelect on CommandItem
- File: provider-multi-select.tsx
4. MEDIUM: Fix double-toggle in group multi-select
- Remove duplicate onCheckedChange handler
- Keep only onSelect on CommandItem
- File: group-multi-select.tsx
All 28 unit tests pass after fixes.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary of ChangesHello @miraserver, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses several critical security and user experience issues within the request filters feature, identified through an AI code review. It prevents sensitive API keys from being exposed to the client, mitigates a potential ReDoS vulnerability by validating regular expressions, and resolves UI flickers in multi-select components. These changes enhance the security posture and improve the overall user experience of the request filtering functionality. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses several important issues, including a critical security vulnerability related to API key leakage and a high-severity ReDoS vulnerability. The changes are well-structured and clearly explained in the description. The fix to prevent passing full provider objects to client components is correctly implemented, and the addition of safeRegex checks provides a necessary layer of security. The UX fixes for the multi-select components are also straightforward and correct. I have one minor suggestion in src/lib/request-filter-engine.ts to improve logging consistency in a test helper, but overall this is an excellent set of fixes.
src/lib/request-filter-engine.ts
Outdated
| } catch { | ||
| // ignore | ||
| } |
There was a problem hiding this comment.
For consistency with the reload method, it would be beneficial to log a warning if the RegExp compilation fails, even within this test helper. Silently ignoring errors can make debugging tests more difficult if a regex passes the safeRegex check but is still syntactically invalid.
} catch (error) {
logger.warn("[RequestFilterEngine] Failed to compile regex in test", {
filterId: f.id,
target: f.target,
error,
});
}Add explicit error logging when regex compilation fails in test helper for consistency with reload() method and easier test debugging. Suggested by: @gemini-code-assist 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review Summary
This PR effectively addresses 4 bugs from PR #487, including 2 security issues (API key leak and ReDoS vulnerability) and 2 UX fixes (double-toggle in multi-select components). The changes are minimal, focused, and follow established patterns in the codebase.
PR Size: S
- Lines changed: 49 (30 additions, 19 deletions)
- Files changed: 5
Issues Found
| Category | Critical | High | Medium | Low |
|---|---|---|---|---|
| Logic/Bugs | 0 | 0 | 0 | 0 |
| Security | 0 | 0 | 0 | 0 |
| Error Handling | 0 | 0 | 0 | 0 |
| Types | 0 | 0 | 0 | 0 |
| Comments/Docs | 0 | 0 | 0 | 0 |
| Tests | 0 | 0 | 0 | 0 |
| Simplification | 0 | 0 | 0 | 0 |
Review Coverage
- Logic and correctness - Clean
- Security (OWASP Top 10) - Clean
- Error handling - Clean
- Type safety - Clean
- Documentation accuracy - Clean
- Test coverage - Adequate (existing test covers unsafe regex scenario)
- Code clarity - Good
Notable Changes
Security Fix 1 - Provider API Key Leak (page.tsx, filter-table.tsx)
The PR correctly removes the Provider type from the client component and changes the prop type to Array<{ id: number; name }>. This prevents the key field from being serialized into the browser bundle.
Security Fix 2 - ReDoS Protection (request-filter-engine.ts)
The PR adds safeRegex() validation before compiling regex patterns, following the established pattern from error-rule-detector.ts. Unsafe patterns are logged and skipped with appropriate warning messages.
UX Fix 3 & 4 - Double-toggle Removal
The duplicate onCheckedChange handlers are correctly removed from both multi-select components, fixing the double-toggle behavior.
All changes are well-tested, follow the project's coding standards, and maintain backward compatibility.
Automated review by Claude AI
Summary
This PR addresses 4 bugs identified by Codex AI code review in PR #487 for the request filters feature (originally from PR #484).
Context: PR #484 was merged before these security fixes were pushed. This PR applies the fixes to
devbranch.Bugs Fixed
1. 🔴 CRITICAL — Provider API Keys Leak to Browser (Security)
Issue: Full
Providerobjects (including secretkeyfield) were passed to client component, causing Next.js to serialize API keys into browser bundle.Files:
src/app/[locale]/settings/request-filters/page.tsxsrc/app/[locale]/settings/request-filters/_components/filter-table.tsxFix: Only pass
{id, name}to client component, removeProvidertype import.Risk: HIGH — Upstream provider API keys exposed to end users
2. 🟠 HIGH — ReDoS Vulnerability in Pre-compiled Regex (Security)
Issue:
compiledRegexwas created withoutsafeRegex()validation, allowing potentially malicious regex patterns from database to execute in proxy hot path.File:
src/lib/request-filter-engine.tsFix:
safeRegex()check before compiling regex inreload()safeRegex()check insetFiltersForTest()Risk: MEDIUM — ReDoS attack possible if admin adds malicious regex pattern
3. 🟡 MEDIUM — Double-toggle in Provider Multi-select (UX)
Issue: Clicking checkbox triggers both
onSelectandonCheckedChangehandlers, causing double-toggle (results in no-op but visible flicker).File:
src/app/[locale]/settings/request-filters/_components/provider-multi-select.tsxFix: Remove duplicate
onCheckedChangehandler, keep onlyonSelectonCommandItem.4. 🟡 MEDIUM — Double-toggle in Group Multi-select (UX)
Issue: Same double-toggle issue as provider multi-select.
File:
src/app/[locale]/settings/request-filters/_components/group-multi-select.tsxFix: Remove duplicate
onCheckedChangehandler.Testing
Files Changed
Total: 5 files, +29/-15 lines
Related PRs
dev)dev→main) — will include these fixes after merge🤖 Generated with Claude Code
Greptile Summary
This PR addresses 4 critical security and UX bugs identified in the request filters feature from PR #484. The changes are focused, well-tested, and production-ready.
Security Fixes:
Providerobjects to client bundle by filtering provider data to only{id, name}before passing to client components. TheProvider.keyfield containing upstream API keys is no longer exposed in browser bundles.safeRegex()validation before compiling regex patterns in bothreload()andsetFiltersForTest()methods. Unsafe patterns are now skipped with warning logs, preventing Regular Expression Denial of Service attacks via malicious regex in the database.UX Fixes:
onCheckedChangehandlers from bothProviderMultiSelectandGroupMultiSelectcomponents. TheCommandItemwrapper'sonSelecthandler is sufficient, eliminating the double-toggle bug that caused flickering.All fixes are minimal, surgical changes that don't affect other functionality. The PR description accurately describes each issue and fix.
Confidence Score: 5/5
safe-regexlibrary, comprehensive test coverage mentioned in PR description (28 tests pass), and clear alignment with the PR descriptionImportant Files Changed
Sequence Diagram
sequenceDiagram participant User participant Page as page.tsx (Server) participant DB as Database participant FilterTable as FilterTable (Client) participant MultiSelect as Multi-Select (Client) User->>Page: Load Request Filters Page Page->>DB: findAllProviders() DB-->>Page: Full Provider objects (with key field) Note over Page: SECURITY FIX:<br/>Filter sensitive data Page->>Page: providers.map(p => ({id, name})) Page->>FilterTable: Pass filtered providers<br/>(id, name only) Note over FilterTable: API keys NOT exposed<br/>to client bundle FilterTable->>MultiSelect: Open provider selection MultiSelect->>MultiSelect: Click checkbox Note over MultiSelect: UX FIX:<br/>Single onSelect handler<br/>(no double-toggle) MultiSelect-->>FilterTable: Provider IDs selected FilterTable->>DB: Save filter with provider IDs DB->>DB: Compile regex with<br/>safeRegex() validation Note over DB: SECURITY FIX:<br/>ReDoS prevention DB-->>FilterTable: Filter saved