Commit 0380d81
committed
Harden NSConnection security in handling third-party connections
Currently, MacVim uses Distributed Objects / NSConnection as the IPC
mechanism. The child Vim process connects to the parent MacVim process
using NSConnection and registers itself. A security issue with this is
that NSConnection is global, and any process can connect to the app, and
MacVim isn't too hardened against this issue. Note that one reason why
we do need the ability for the MacVim app to accept random connections
is to support the `:gui` command from a random Vim process, and to
supported listing server names.
One issue is that while the app protocol (MMAppProtocol) is only a few
functions, we were exposing the entire app, which exposes functions like
`executeInLoginShell`, which could be invoked by the caller, which is
quite unsafe as it could be invoked by any third-party app. Fix this
issue by using `NSProtocolChecker` to make sure we only expose the APIs
that we want to expose.
Each Vim controller now also gets a randomized ID instead of an
incremental one. Currently the API for sending messages from Vim to
MacVim is public, meaning any app can send message to MacVim. Using a
randomized ID makes it more difficult for an attacker to guess the ID
(which used to always start at 1) and injects random commands to MacVim
pretending to be the Vim process.
Also, make sure if MacVim failed to register the NSConnection on launch,
just display an error and terminate. This usually happens if multiple
MacVim instances are opened, but also if an attacking app is trying to
register a connection first using the same name. This way the user would
know something is wrong instead of MacVim being opened by not able to do
anything as it didn't register the connection.
In the near future, the IPC mechanism will be switched to XPC, which is
the preferred way by Apple as Distributed Objects has been deprecated
for a long time. It will have proper security to only accept processes
within the same app to message each other. It will be done in #1157.1 parent 64f4004 commit 0380d81
File tree
6 files changed
+53
-28
lines changed- src/MacVim
- MacVim.xcodeproj
6 files changed
+53
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
308 | 310 | | |
309 | 311 | | |
310 | 312 | | |
| |||
315 | 317 | | |
316 | 318 | | |
317 | 319 | | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
318 | 334 | | |
319 | 335 | | |
320 | 336 | | |
| |||
859 | 875 | | |
860 | 876 | | |
861 | 877 | | |
862 | | - | |
| 878 | + | |
863 | 879 | | |
864 | 880 | | |
865 | 881 | | |
| |||
1540 | 1556 | | |
1541 | 1557 | | |
1542 | 1558 | | |
1543 | | - | |
| 1559 | + | |
1544 | 1560 | | |
1545 | 1561 | | |
1546 | 1562 | | |
| |||
1570 | 1586 | | |
1571 | 1587 | | |
1572 | 1588 | | |
1573 | | - | |
| 1589 | + | |
1574 | 1590 | | |
1575 | 1591 | | |
1576 | 1592 | | |
1577 | 1593 | | |
1578 | 1594 | | |
1579 | 1595 | | |
1580 | | - | |
| 1596 | + | |
1581 | 1597 | | |
1582 | 1598 | | |
1583 | 1599 | | |
1584 | | - | |
| 1600 | + | |
1585 | 1601 | | |
1586 | 1602 | | |
1587 | | - | |
| 1603 | + | |
1588 | 1604 | | |
1589 | 1605 | | |
1590 | 1606 | | |
| |||
2715 | 2731 | | |
2716 | 2732 | | |
2717 | 2733 | | |
2718 | | - | |
| 2734 | + | |
2719 | 2735 | | |
2720 | 2736 | | |
2721 | 2737 | | |
| |||
2737 | 2753 | | |
2738 | 2754 | | |
2739 | 2755 | | |
2740 | | - | |
| 2756 | + | |
2741 | 2757 | | |
2742 | 2758 | | |
2743 | 2759 | | |
| |||
2758 | 2774 | | |
2759 | 2775 | | |
2760 | 2776 | | |
2761 | | - | |
| 2777 | + | |
2762 | 2778 | | |
2763 | 2779 | | |
2764 | 2780 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | 59 | | |
62 | 60 | | |
63 | 61 | | |
| |||
168 | 166 | | |
169 | 167 | | |
170 | 168 | | |
171 | | - | |
172 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
173 | 178 | | |
174 | 179 | | |
175 | 180 | | |
| |||
257 | 262 | | |
258 | 263 | | |
259 | 264 | | |
260 | | - | |
| 265 | + | |
261 | 266 | | |
262 | 267 | | |
263 | 268 | | |
| |||
436 | 441 | | |
437 | 442 | | |
438 | 443 | | |
439 | | - | |
| 444 | + | |
440 | 445 | | |
441 | 446 | | |
442 | 447 | | |
| |||
468 | 473 | | |
469 | 474 | | |
470 | 475 | | |
471 | | - | |
| 476 | + | |
472 | 477 | | |
473 | 478 | | |
474 | 479 | | |
| |||
500 | 505 | | |
501 | 506 | | |
502 | 507 | | |
503 | | - | |
| 508 | + | |
504 | 509 | | |
505 | 510 | | |
506 | 511 | | |
| |||
517 | 522 | | |
518 | 523 | | |
519 | 524 | | |
520 | | - | |
| 525 | + | |
521 | 526 | | |
522 | 527 | | |
523 | 528 | | |
| |||
556 | 561 | | |
557 | 562 | | |
558 | 563 | | |
559 | | - | |
| 564 | + | |
560 | 565 | | |
561 | 566 | | |
562 | 567 | | |
| |||
1275 | 1280 | | |
1276 | 1281 | | |
1277 | 1282 | | |
1278 | | - | |
| 1283 | + | |
1279 | 1284 | | |
1280 | 1285 | | |
1281 | 1286 | | |
| |||
1308 | 1313 | | |
1309 | 1314 | | |
1310 | 1315 | | |
1311 | | - | |
| 1316 | + | |
1312 | 1317 | | |
1313 | 1318 | | |
1314 | 1319 | | |
| |||
2089 | 2094 | | |
2090 | 2095 | | |
2091 | 2096 | | |
2092 | | - | |
| 2097 | + | |
2093 | 2098 | | |
2094 | 2099 | | |
2095 | 2100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
| 200 | + | |
201 | 201 | | |
202 | | - | |
| 202 | + | |
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| |||
423 | 424 | | |
424 | 425 | | |
425 | 426 | | |
| 427 | + | |
426 | 428 | | |
427 | 429 | | |
428 | 430 | | |
| |||
462 | 464 | | |
463 | 465 | | |
464 | 466 | | |
| 467 | + | |
465 | 468 | | |
466 | 469 | | |
467 | 470 | | |
| |||
650 | 653 | | |
651 | 654 | | |
652 | 655 | | |
| 656 | + | |
653 | 657 | | |
654 | 658 | | |
655 | 659 | | |
| |||
0 commit comments