-
Notifications
You must be signed in to change notification settings - Fork 2
Add cache handlers package #19
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
base: main
Are you sure you want to change the base?
Conversation
…n permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|
… sanitization Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
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.
Pull Request Overview
This PR adds a comprehensive cache handlers package that provides unified cache management functionality for Web API environments. The package includes cache reading/writing, invalidation operations, conditional request support, and stale-while-revalidate (SWR) handling.
Key changes:
- Complete cache handling implementation with read/write operations and invalidation support
- Unified configuration system with TypeScript tooling setup
- Comprehensive test coverage across Node.js, Deno, and workerd environments
Reviewed Changes
Copilot reviewed 71 out of 76 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tsdown.config.ts | Root build configuration for TypeScript compilation |
| tsconfig.base.json | Updated base TypeScript configuration with modern settings |
| pnpm-workspace.yaml | Added demos directory to workspace |
| packages/cdn-cache-control/package.json | Fixed repository URL format |
| packages/cache-handlers/ | Complete cache handlers implementation with source files, tests, and configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if (tags.length > 100) { | ||
| throw new Error("Too many cache tags (max 100)"); |
Copilot
AI
Aug 24, 2025
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 magic number 100 for maximum cache tags should be defined as a named constant to improve maintainability and make it configurable.
| if (tags.length > 100) { | |
| throw new Error("Too many cache tags (max 100)"); | |
| if (tags.length > MAX_CACHE_TAGS) { | |
| throw new Error(`Too many cache tags (max ${MAX_CACHE_TAGS})`); |
| if (tag.length > 100) { | ||
| throw new Error("Cache tag too long (max 100 characters)"); |
Copilot
AI
Aug 24, 2025
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 magic number 100 for maximum tag length should be defined as a named constant to improve maintainability and allow for easier configuration changes.
| if (tag.length > 100) { | |
| throw new Error("Cache tag too long (max 100 characters)"); | |
| if (tag.length > MAX_CACHE_TAG_LENGTH) { | |
| throw new Error(`Cache tag too long (max ${MAX_CACHE_TAG_LENGTH} characters)`); |
| // Remove ALL control characters (0-31) and DEL (127) except space (32) | ||
| // deno-lint-ignore no-control-regex | ||
| const sanitized = tag.replace(/[\x00-\x1F\x7F]/g, "").trim(); | ||
|
|
||
| if (sanitized.length === 0) { | ||
| throw new Error("Cache tag cannot be empty after sanitization"); | ||
| } | ||
|
|
||
| // Validate against common injection patterns | ||
| if ( | ||
| sanitized.includes("<") || | ||
| sanitized.includes(">") || | ||
| sanitized.includes('"') | ||
| ) { | ||
| throw new Error('Cache tag contains invalid characters (<, >, ")'); | ||
| } | ||
|
|
||
| return sanitized; |
Copilot
AI
Aug 24, 2025
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 regex removes control characters but the sanitization approach could be more comprehensive. Consider documenting what characters are allowed and why, as this affects cache security.
| // Remove ALL control characters (0-31) and DEL (127) except space (32) | |
| // deno-lint-ignore no-control-regex | |
| const sanitized = tag.replace(/[\x00-\x1F\x7F]/g, "").trim(); | |
| if (sanitized.length === 0) { | |
| throw new Error("Cache tag cannot be empty after sanitization"); | |
| } | |
| // Validate against common injection patterns | |
| if ( | |
| sanitized.includes("<") || | |
| sanitized.includes(">") || | |
| sanitized.includes('"') | |
| ) { | |
| throw new Error('Cache tag contains invalid characters (<, >, ")'); | |
| } | |
| return sanitized; | |
| // Only allow [A-Za-z0-9._-] | |
| const allowedTag = tag.trim(); | |
| if (!/^[A-Za-z0-9._-]+$/.test(allowedTag)) { | |
| throw new Error( | |
| "Cache tag contains invalid characters. Allowed: A-Z, a-z, 0-9, dash (-), underscore (_), period (.)" | |
| ); | |
| } | |
| return allowedTag; |
d078e3b to
119004b
Compare
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
cache-handlers | 7d6c604 | Commit Preview URL Branch Preview URL |
Sep 02 2025, 08:18 AM |
No description provided.