Repository navigation
Conversation
- FastGateway.sln 缺少测试项目的 ProjectConfigurationPlatforms 映射, dotnet build / dotnet test FastGateway.sln 会完全忽略测试项目并静默返回 0, AGENTS.md 推荐的回归命令因此是假通过 - FrameOptionsTests 增加 3 个用例:配置 JSON round-trip、 旧版 gateway.config 缺字段回退 SAMEORIGIN、集群 MessagePack 同步 round-trip - .NET 11 回归:dotnet build FastGateway.sln 0 错误, dotnet test FastGateway.sln 246/246 通过
There was a problem hiding this comment.
🟡 Changes recommended
Concurrent configuration reloads can overwrite newer policies with stale snapshots, leaving revoked origins allowed even after successful saves.
3 open issues
What changed in this PR
Adds dashboard-managed origin rules for gateway CORS and WebSockets, with exact-domain and wildcard matching, persistent overrides, and immediate application to new requests.
Changes:
- Adds origin-settings APIs and a dashboard editor with save and reset actions.
- Introduces shared origin validation and live policy updates.
- Documents configuration behavior and expands origin-policy and compatibility tests.
| File | Description |
|---|---|
web/src/services/SettingService.ts |
Adds typed origin-settings API calls. |
web/src/pages/system-setting/page.tsx |
Displays the origin-settings card. |
web/src/pages/system-setting/features/OriginSettingsCard.tsx |
Adds origin editing, saving, and reset controls. |
tests/FastGateway.Tests/OriginPolicyTests.cs |
Tests matching, persistence, authorization, CORS, and WebSockets. |
tests/FastGateway.Tests/FrameOptionsTests.cs |
Adds serialization and legacy-configuration coverage. |
src/FastGateway/Services/SettingService.cs |
Exposes origin-settings endpoints. |
src/FastGateway/Services/ConfigurationService.cs |
Adds rollback-safe managed-setting persistence. |
src/FastGateway/Risk/RiskSigningKey.cs |
Marks origin settings as managed. |
src/FastGateway/Program.cs |
Initializes the shared origin policy. |
src/FastGateway/Infrastructure/AppJsonContext.cs |
Registers origin DTOs for source-generated JSON serialization. |
src/FastGateway/Gateway/OriginPolicyStore.cs |
Implements matching, policy storage, and WebSocket checks. |
src/FastGateway/Gateway/Gateway.cs |
Integrates dynamic origin checks into gateway middleware. |
README.md |
Documents origin configuration in English. |
README-zh-cn.md |
Documents origin configuration in Chinese. |
FastGateway.sln |
Adds test-project build configuration mappings. |
CHANGELOG.md |
Records test infrastructure and compatibility coverage updates. |
.gitignore |
Ignores the local CORS HTTP request file. |
Review effort: Balanced
| if (setting != null && setting.Value == null) | ||
| throw new ValidationException("跨域来源配置不能为空值"); | ||
| var origins = setting == null ? _fallback : setting.Value.Length == 0 ? [] : setting.Value.Split('\n'); | ||
| Volatile.Write(ref _current, new OriginPolicy(origins)); |
| var wildcard = bareWildcard || value.StartsWith("http://*.", StringComparison.OrdinalIgnoreCase) || | ||
| value.StartsWith("https://*.", StringComparison.OrdinalIgnoreCase); | ||
| var input = bareWildcard ? "https://placeholder." + value[2..] : | ||
| wildcard ? value.Replace("*.", "placeholder.", StringComparison.Ordinal) : value; |
Comment on lines
+36
to
+51
| ? uri.Host.Length > rule.Host.Length + 1 && | ||
| uri.Host.EndsWith("." + rule.Host, StringComparison.OrdinalIgnoreCase) | ||
| : string.Equals(uri.Host, rule.Host, StringComparison.OrdinalIgnoreCase))); | ||
| } | ||
|
|
||
| private static bool TryParseRule(string value, out Rule? rule) | ||
| { | ||
| rule = null; | ||
| var bareWildcard = value.StartsWith("*.", StringComparison.Ordinal); | ||
| if (bareWildcard && value.Contains(':')) return false; | ||
| var wildcard = bareWildcard || value.StartsWith("http://*.", StringComparison.OrdinalIgnoreCase) || | ||
| value.StartsWith("https://*.", StringComparison.OrdinalIgnoreCase); | ||
| var input = bareWildcard ? "https://placeholder." + value[2..] : | ||
| wildcard ? value.Replace("*.", "placeholder.", StringComparison.Ordinal) : value; | ||
| if (!TryParseUri(input, out var uri)) return false; | ||
| var host = uri.Host; |
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.


新增跨域来源管理界面,支持精确域名和通配符,配置保存后立即生效。
Motivation and Context
此前跨域来源主要依赖配置文件或环境变量,维护不便,且无法灵活配置子域名。
How Has This Been Tested?
Breaking Changes
现有有效配置无需修改。无效的来源配置会被拒绝;界面配置优先于环境变量和配置文件。
Types of changes
Checklist
Additional context