Commit 211846a
authored
fix: prevent subdomain confusion attacks in RPC domain validation (#17234)
Replace vulnerable `endsWith()` with secure dot-prefix validation to
prevent malicious domains like 'evilinfura.io' from being misclassified.
- Add `ALLOWED_PROVIDER_DOMAINS` constant for clear business logic
- Add `isAllowedProviderDomain()` with secure `endsWith('.${domain}')`
validation
- Simplify `extractRpcDomain()` provider validation logic
- Add comprehensive security tests and edge case coverage
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **Description**
This PR fixes a security vulnerability where `extractRpcDomain()` used
vulnerable `endsWith()` checks that allowed subdomain confusion attacks.
Malicious domains like `evilinfura.io` or `fakealchemyapi.io` were
incorrectly classified as legitimate provider domains.
**What is the reason for the change?**
The security audit flagged "Incomplete URL substring sanitization"
because `endsWith('infura.io')` accepts any domain ending with those
characters, including malicious domains.
**What is the improvement/solution?**
Replaced vulnerable `endsWith('infura.io')` with secure
`endsWith('.infura.io')` validation. The dot prefix ensures only
legitimate subdomains are accepted:
- ✅ `mainnet.infura.io` ends with `.infura.io` → legitimate subdomain
- ❌ `evilinfura.io` does NOT end with `.infura.io` → blocked as
malicious
## **Changelog**
CHANGELOG entry: Fixed security vulnerability in RPC domain validation
that could allow malicious domains to be misclassified as legitimate
providers
## **Related issues**
Fixes: Security audit finding - "Incomplete URL substring sanitization"
## **Manual testing steps**
1. **Verify existing RPC domain tracking works**:
- Submit transactions using default Infura RPC
- Check logs show `"rpc_domain": "mainnet.infura.io"` in MetaMetrics
events
- Confirm both "Transaction Approved" and "Transaction Finalized" events
include the property
2. **Security validation through unit tests**:
- Run `yarn test app/util/rpc-domain-utils.test.ts` to verify:
- Legitimate domains work: `mainnet.infura.io` → `"mainnet.infura.io"`
- Malicious domains blocked: `evilinfura.io` → `"private"`
- The security fix prevents subdomain confusion attacks
3. **Verification summary**:
- Manual testing confirms existing functionality is preserved
- Unit tests validate the security vulnerability is fixed
## **Screenshots/Recordings**
https://github.com/user-attachments/assets/dcb9f1f0-a908-4de1-8a61-ab4aa41cde77
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [x] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.1 parent 1b6ee57 commit 211846a
File tree
3 files changed
+143
-7
lines changed- app/util
3 files changed
+143
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
306 | 420 | | |
| 421 | + | |
307 | 422 | | |
308 | 423 | | |
309 | 424 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
119 | 139 | | |
120 | 140 | | |
121 | 141 | | |
| |||
126 | 146 | | |
127 | 147 | | |
128 | 148 | | |
| 149 | + | |
129 | 150 | | |
130 | 151 | | |
131 | 152 | | |
132 | 153 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
140 | 157 | | |
141 | 158 | | |
| 159 | + | |
142 | 160 | | |
143 | 161 | | |
144 | 162 | | |
145 | 163 | | |
| 164 | + | |
146 | 165 | | |
147 | 166 | | |
148 | 167 | | |
| |||
0 commit comments