Commit 4df1191
fix(server): sanitize error responses to prevent stack trace exposure (#1187)
* fix(server): sanitize error responses to prevent stack trace exposure
Replace raw error objects passed to res.json() with generic sanitized
messages so internal error details are not leaked to clients. Full
errors continue to be logged server-side via console.error.
Also adds a missing return in the /sse ECONNREFUSED branch, which
previously fell through and attempted a second response after headers
had already been sent.
Resolves CodeQL js/stack-trace-exposure alerts in server/src/index.ts.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(server): address review feedback on error sanitization
- Sanitize /fetch route catch block: previously leaked error.message to
clients and silently swallowed errors with no server-side logging.
Now logs via console.error and returns a generic sanitized response.
- Replace JSON.stringify(error).includes("ECONNREFUSED") in the /sse
handler with a check against error.message and String(error.cause).
Error fields are non-enumerable so JSON.stringify(new Error(...))
produces "{}" — the old check only worked by accident when the error
happened to carry enumerable properties.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Ola Hungerford <olahungerford@gmail.com>1 parent 0d7757e commit 4df1191
1 file changed
Lines changed: 45 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
75 | 88 | | |
76 | 89 | | |
77 | | - | |
| 90 | + | |
| 91 | + | |
78 | 92 | | |
79 | 93 | | |
80 | 94 | | |
81 | | - | |
82 | 95 | | |
83 | 96 | | |
84 | 97 | | |
| |||
92 | 105 | | |
93 | 106 | | |
94 | 107 | | |
95 | | - | |
| 108 | + | |
96 | 109 | | |
97 | 110 | | |
98 | 111 | | |
| |||
509 | 522 | | |
510 | 523 | | |
511 | 524 | | |
512 | | - | |
| 525 | + | |
513 | 526 | | |
514 | 527 | | |
515 | 528 | | |
| |||
545 | 558 | | |
546 | 559 | | |
547 | 560 | | |
548 | | - | |
| 561 | + | |
549 | 562 | | |
550 | 563 | | |
551 | 564 | | |
| |||
592 | 605 | | |
593 | 606 | | |
594 | 607 | | |
595 | | - | |
| 608 | + | |
596 | 609 | | |
597 | 610 | | |
598 | 611 | | |
599 | | - | |
| 612 | + | |
600 | 613 | | |
601 | 614 | | |
602 | 615 | | |
| |||
627 | 640 | | |
628 | 641 | | |
629 | 642 | | |
630 | | - | |
| 643 | + | |
631 | 644 | | |
632 | 645 | | |
633 | 646 | | |
| |||
732 | 745 | | |
733 | 746 | | |
734 | 747 | | |
735 | | - | |
| 748 | + | |
736 | 749 | | |
737 | 750 | | |
738 | 751 | | |
739 | | - | |
| 752 | + | |
740 | 753 | | |
741 | 754 | | |
742 | 755 | | |
| |||
781 | 794 | | |
782 | 795 | | |
783 | 796 | | |
784 | | - | |
| 797 | + | |
785 | 798 | | |
786 | 799 | | |
787 | 800 | | |
788 | 801 | | |
789 | 802 | | |
790 | | - | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
791 | 808 | | |
792 | | - | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
793 | 814 | | |
794 | | - | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
795 | 821 | | |
796 | 822 | | |
797 | | - | |
| 823 | + | |
798 | 824 | | |
799 | 825 | | |
800 | 826 | | |
| |||
824 | 850 | | |
825 | 851 | | |
826 | 852 | | |
827 | | - | |
| 853 | + | |
828 | 854 | | |
829 | 855 | | |
830 | 856 | | |
| |||
882 | 908 | | |
883 | 909 | | |
884 | 910 | | |
885 | | - | |
886 | | - | |
887 | | - | |
| 911 | + | |
| 912 | + | |
888 | 913 | | |
889 | 914 | | |
890 | 915 | | |
| |||
900 | 925 | | |
901 | 926 | | |
902 | 927 | | |
903 | | - | |
| 928 | + | |
904 | 929 | | |
905 | 930 | | |
906 | 931 | | |
| |||
0 commit comments