Commit 4c2fc01
authored
Generate safe javascript url instead of throwing with disableJavaScriptURLs is on (#26507)
We currently throw an error when disableJavaScriptURLs is on and trigger
an error boundary. I kind of thought that's what would happen with CSP
or Trusted Types anyway. However, that's not what happens. Instead, in
those environments what happens is that the error is triggered when you
try to actually visit those links. So if you `preventDefault()` or
something it'll never show up and since the error just logs to the
console or to a violation logger, it's effectively a noop to users.
We can simulate the same without CSP by simply generating a different
`javascript:` url that throws instead of executing the potential attack
vector.
This still allows these to be used - at least as long as you
preventDefault before using them in practice. This might be legit for
forms. We still don't recommend using them for links-as-buttons since
it'll be possible to "Open in a New Tab" and other weird artifacts. For
links we still recommend the technique of assigning a button role etc.
It also is a little nicer when an attack actually happens because at
least it doesn't allow an attacker to trigger error boundaries and
effectively deny access to a page.1 parent f0aafa1 commit 4c2fc01
File tree
4 files changed
+233
-142
lines changed- packages
- react-dom-bindings/src
- client
- server
- react-dom/src/__tests__
4 files changed
+233
-142
lines changedLines changed: 28 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| |||
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | 45 | | |
56 | 46 | | |
57 | 47 | | |
| |||
134 | 124 | | |
135 | 125 | | |
136 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
137 | 132 | | |
138 | 133 | | |
139 | 134 | | |
| |||
175 | 170 | | |
176 | 171 | | |
177 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
178 | 183 | | |
179 | 184 | | |
180 | 185 | | |
| |||
395 | 400 | | |
396 | 401 | | |
397 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
398 | 406 | | |
399 | 407 | | |
400 | 408 | | |
401 | 409 | | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
406 | 414 | | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
407 | 418 | | |
408 | | - | |
409 | | - | |
410 | | - | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
411 | 422 | | |
412 | 423 | | |
413 | 424 | | |
| |||
Lines changed: 16 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
736 | 736 | | |
737 | 737 | | |
738 | 738 | | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
739 | 742 | | |
740 | | - | |
741 | | - | |
742 | | - | |
743 | | - | |
744 | | - | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
745 | 746 | | |
746 | 747 | | |
747 | 748 | | |
| |||
3844 | 3845 | | |
3845 | 3846 | | |
3846 | 3847 | | |
3847 | | - | |
3848 | | - | |
| 3848 | + | |
| 3849 | + | |
3849 | 3850 | | |
3850 | 3851 | | |
3851 | | - | |
3852 | | - | |
3853 | | - | |
3854 | | - | |
3855 | | - | |
| 3852 | + | |
| 3853 | + | |
3856 | 3854 | | |
3857 | 3855 | | |
3858 | 3856 | | |
| |||
3939 | 3937 | | |
3940 | 3938 | | |
3941 | 3939 | | |
3942 | | - | |
3943 | | - | |
| 3940 | + | |
3944 | 3941 | | |
3945 | 3942 | | |
3946 | 3943 | | |
| |||
4041 | 4038 | | |
4042 | 4039 | | |
4043 | 4040 | | |
4044 | | - | |
4045 | | - | |
| 4041 | + | |
| 4042 | + | |
4046 | 4043 | | |
4047 | 4044 | | |
4048 | | - | |
4049 | | - | |
4050 | | - | |
4051 | | - | |
4052 | | - | |
| 4045 | + | |
| 4046 | + | |
4053 | 4047 | | |
4054 | 4048 | | |
4055 | 4049 | | |
| |||
4136 | 4130 | | |
4137 | 4131 | | |
4138 | 4132 | | |
4139 | | - | |
4140 | | - | |
| 4133 | + | |
4141 | 4134 | | |
4142 | 4135 | | |
4143 | 4136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
28 | 31 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
33 | 37 | | |
34 | 38 | | |
35 | | - | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
41 | | - | |
| 45 | + | |
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
| 49 | + | |
45 | 50 | | |
46 | 51 | | |
47 | 52 | | |
0 commit comments