AlexStocks opened a new issue, #3:
URL: https://github.com/apache/dubbo-net/issues/3
## 概述
导入的源码里有约 700 行**完全未被引用**的工具代码,其中两处具有真实安全含义。建议在导入稳定后立即删除,不要让它随 NuGet 包发布。
## 1. `NetService/MyWebTool.cs` —— 会全局关闭宿主进程的 TLS 校验
`MyWebTool.cs:471-497`:
```csharp
static MyHttp()
{
ServicePointManager.ServerCertificateValidationCallback =
MyRemoteCertificateValidationCallback;
System.Net.ServicePointManager.DefaultConnectionLimit = 2000;
}
private static bool enableServerCertificateValidation = false;
private static bool MyRemoteCertificateValidationCallback(object sender,
X509Certificate certificate,
X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (enableServerCertificateValidation && sslPolicyErrors !=
SslPolicyErrors.None) return false;
return true; // enableServerCertificateValidation 默认 false → 一律接受
}
```
问题在于 `ServicePointManager.ServerCertificateValidationCallback` 是**进程级全局状态**:
- 它不只影响 `MyHttp` 自己,而是影响宿主应用里所有走 `HttpWebRequest` / 兼容 handler 的请求。
- 触发条件极低:只要宿主代码**碰到一次**这个 public 类(静态构造即执行),TLS 校验就被静默关闭。
- 一个库在静态构造里改全局安全设置,是明确的越权。
目前 `MyHttp` 在仓库内零引用(`HttpDubboActuatorSuite` 用的是独立的
`SocketsHttpHandler`),属于死代码,但它仍会出现在发布的公开 API 里。
## 2. `MyCommonHelper/EncryptionHelper/` —— 未使用的弱加密 + 真 bug
引用情况(仅 `MyHash.GetMurmurHash2` 被 `Clients/Helper/ConsistentHash.cs:104` 使用):
| 类 | 文件 | 仓库内引用 |
|---|---|---|
| `MyRC4` | 84 行 | 无 |
| `MyDES` | 52 行 | 无 |
| `MyRSA` | 292 行 | 无 |
| `MyEncryption` | 239 行 | 无 |
| `MyHash` | 56 行 | ✅ 在用 |
顺带修掉的缺陷:
- `MyRSA.cs:25` —— `new ArgumentNullException("Argument Is Null");`
**结果被丢弃,没有 throw**,空值保护形同虚设:
```csharp
if (PlainText == null || modulus == null || publicExponent == null)
{
new ArgumentNullException("Argument Is Null"); // ← 缺少 throw
}
```
- `MyRSA.RSAEncrypt` 用 `catch (Exception) { return null; }`
吞掉所有加密异常,调用方无法区分失败原因。
- `MyRSA.VerifyPwdData` 连续三次覆盖 `isVerify`,前两次计算完全无效,且硬编码 `"123456"`、使用 MD5。
- `MyRSA.DecryptUsingPublic` 语义错误:用 `rsa.Decrypt` 做"公钥解密",RSA 签名验证应走
`VerifyData`。
## 建议
1. 删除 `NetService/MyWebTool.cs`。
2. 删除 `MyCommonHelper/EncryptionHelper/` 下除 `MyHash.cs` 外的全部文件。
3. 若未来确实需要 HTTP 工具,改用 `IHttpClientFactory` / 共享
`SocketsHttpHandler`,且**不要**触碰 `ServicePointManager` 全局状态;证书校验的裁剪必须由使用方显式开启。
删除后跑一次 `dotnet build DubboNet.sln` 确认无残留引用。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]