Conversation
Owner
|
Khắc phục 1: Thiếu xác thực đầu vào trong các ví dụ về tuyến API (,architecture-patterns.mdframework-catalog.md) |
…e as-any assertion Co-authored-by: VoDaiLocz <88762074+VoDaiLocz@users.noreply.github.com>
Owner
Copilot
AI
changed the title
[WIP] Review security audit for all code examples
Security audit: input validation, rate-limit memory leak, unsafe Mar 4, 2026
as any in code examples
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Code examples across the reference docs contained several security and correctness issues that developers could inadvertently replicate in production code.
Changes
Missing input validation in API route examples
architecture-patterns.md— Next.jsPOSThandler now parses the request body throughCreateUserSchema.parse()before passing to the service layerframework-catalog.md— Server ActioncreateUsernow validatesFormDataviaCreateUserSchema.parse()before calling the servicewithRateLimitmemory leak (code-patterns.md)The
Map<string, number>accumulated every unique IP address forever. Replaced with a windowed counterMap<string, { count: number; resetAt: number }>— adds awindowMsparameter; entries reset per window instead of growing unboundedly.Unsafe
as anyassertion in test example (testing-patterns.md)createNotification("pigeon" as any)replaced with// @ts-expect-error, which is the correct TypeScript idiom for testing runtime rejection of invalid inputs without broadly suppressing type checking. Test call signature updated to match newwithRateLimit(limit, windowMs, handler)API.Checked but no changes needed: no hardcoded secrets (config uses env vars), CQRS SQL query uses parameterized
$1, Python Singleton usesthreading.Lock(), TypeScript Singleton is module-level in single-threaded Node.js, EventBuson()already returns an unsubscribe function, andanti-patterns.mdalready documents missing timeouts as a 🔴 High severity anti-pattern with the correct fix.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.