Skip to content

perf: ip check#6850

Merged
c121914yu merged 15 commits into
labring:mainfrom
c121914yu:ip
May 6, 2026
Merged

perf: ip check#6850
c121914yu merged 15 commits into
labring:mainfrom
c121914yu:ip

Conversation

@c121914yu

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings April 29, 2026 02:10
@github-actions

github-actions Bot commented Apr 29, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 14.03% 1139 / 8115
🔵 Statements 14.02% 1194 / 8514
🔵 Functions 12.53% 245 / 1954
🔵 Branches 11.99% 536 / 4468
File CoverageNo changed files found.
Generated in workflow #85 for commit 8c9343c by the Vitest Coverage Report Action

Copilot AI left a comment

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.

Pull request overview

This PR replaces request-ip with a centralized, proxy-aware client IP resolver and updates rate limiting / logging / internal endpoints to use the new logic, aiming to prevent spoofed forwarding headers and improve correctness/performance.

Changes:

  • Added packages/service/common/security/clientIp.ts (proxy-addr + normalization + trusted proxy allowlist via TRUSTED_PROXY_IPS) and comprehensive tests.
  • Updated multiple API/middleware locations to use getClientIpFromRequest / normalizeClientIp instead of request-ip or raw headers.
  • Removed request-ip dependencies and introduced proxy-addr (+ types); updated docs to mention the stronger IP checks.

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
projects/app/src/pages/api/support/user/account/loginByPassword.ts Uses new client IP resolver when creating user sessions.
projects/app/src/pages/api/core/sandbox/proxyCSPassword.ts Normalizes socket IP before internal-only allowlist check.
projects/app/package.json Removes request-ip and its types from app deps.
pnpm-workspace.yaml Adds proxy-addr (+ types) to catalog; request-ip catalog entries still present.
pnpm-lock.yaml Adds proxy-addr (+ types) resolutions; request-ip entries still present.
packages/service/type/env.ts Adds TRUSTED_PROXY_IPS env typing.
packages/service/env.ts Adds USE_IP_LIMIT and TRUSTED_PROXY_IPS to env schema/metadata.
packages/service/common/system/frequencyLimit/utils.ts Fixes rate-limit signaling by throwing/rethrowing tooManyRequest.
packages/service/common/security/clientIp.ts New trusted-proxy-aware client IP parsing + normalization utilities.
packages/service/common/middle/reqFrequencyLimit.ts Switches IP extraction to new resolver and changes enable/disable gating logic.
packages/service/common/middle/entry.ts Uses new resolver for request logging IP field.
packages/service/common/geo/index.ts Uses new resolver for geo IP extraction.
packages/service/test/common/security/clientIp.test.ts Adds unit tests for normalization, proxy trust, and header parsing behavior.
packages/service/test/common/middle/reqFrequencyLimit.test.ts Adds tests ensuring rate limiting uses non-spoofable client IP keys.
packages/service/test/common/geo/index.test.ts Updates/adds tests to reflect trusted-proxy behavior and spoof prevention.
document/data/doc-last-modified.json Updates doc last-modified timestamp.
document/content/self-host/upgrading/4-15/4150.mdx Notes stronger IP detection/spoofing prevention in release notes.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/service/common/middle/reqFrequencyLimit.ts Outdated
Comment thread packages/service/common/security/clientIp.ts
Comment thread packages/service/common/security/clientIp.ts Outdated
Comment thread packages/service/common/security/clientIp.ts Outdated
Comment thread pnpm-workspace.yaml Outdated
Comment thread pnpm-lock.yaml
@github-actions

github-actions Bot commented Apr 29, 2026

Copy link
Copy Markdown

Docs Preview Deployed!

🔗 👀 Click here to visit preview

ghcr.io/labring/fastgpt-docs-pr:8c9343c6b77e8f042b639614c76405ce58bcff18

@github-actions

github-actions Bot commented Apr 29, 2026

Copy link
Copy Markdown

Build Successful - Preview code-sandbox Image for this PR:

ghcr.io/labring/fastgpt-pr:code-sandbox_8c9343c6b77e8f042b639614c76405ce58bcff18

@github-actions

github-actions Bot commented Apr 29, 2026

Copy link
Copy Markdown

Build Successful - Preview fastgpt Image for this PR:

ghcr.io/labring/fastgpt-pr:fastgpt_8c9343c6b77e8f042b639614c76405ce58bcff18

@github-actions

github-actions Bot commented Apr 29, 2026

Copy link
Copy Markdown

Build Successful - Preview mcp_server Image for this PR:

ghcr.io/labring/fastgpt-pr:mcp_server_8c9343c6b77e8f042b639614c76405ce58bcff18

@github-actions

github-actions Bot commented Apr 29, 2026

Copy link
Copy Markdown

Admin Preview Image Ready!

ghcr.io/labring/fastgpt-pr:admin_8c9343c6b77e8f042b639614c76405ce58bcff18

@xqvvu xqvvu self-assigned this Apr 29, 2026
@xqvvu
xqvvu force-pushed the ip branch 2 times, most recently from dd3e1f9 to 20516e7 Compare May 6, 2026 08:20
@c121914yu
c121914yu merged commit f252bc7 into labring:main May 6, 2026
8 checks passed
@c121914yu
c121914yu deleted the ip branch May 26, 2026 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants