Commit 697a045
fix(pageAPI): Apply Regex and sanitization correctly (dotCMS#31422)
### Problems found
1. Regarding the first mentioned issue, the vanityUrl was trying to
redirect to $1, this is because when handling regex in vanityUrl a
function was needed to be executed to process the url and get the final
one that the page should be redirected to, and in the cases of Temporary
and Permanent Redirect that function was not being executed
2. About the second issue, it was a case that was not being contemplated
when using vanityUrls. As the uri is `(.*)/index` and the forwardTo `$1`
this resulted in an empty string url that was generating a blank page
when accesing through browser.
3. Also the regex of the second issue was generating an infinite loop in
the UVE, this was because it was trying to forward to an empty string.
The frontend of the UVE was handling this case and fallbacking to
`index` in the url, then navigating to pageAPI to render `index` but
then the backend finds that there is a vanityUrl and forwards to empty
string, then the frontend redirects again to `index` and so on.
### Proposed Changes
* To solve the problem **1**: Apply a workaround to modify the forwardTo
value (executing the function that processes the url) and set it to the
CachedVanityUrl which is the entity used in the Temporary and Permanent
Redirect case. This way in those cases the forwardTo is going to be
correct, and return to the frontend as it should.
* To solve the problem **2**: Add an extra check in the `processForward`
function that verifies if the forward url is empty (this means that the
forward should redirect to the root) then set `/` as the final url. This
will make the url work as it should in the browser.
* To solve the problem **3**: Modify what the frontend send to the
backend in the cases where it receives from the frontend an empty url.
Instead of index, send to the backend `/`, this will result in the same
behaviour as index, but allowing the user to handle this last case. Now
when using a vanityUrl with `index` in the regex, and forwarding to `/`
it won't generate an infinite loop.
* Additional fix: when using a vanityUrl with regex, and forwarding to
an url that matches with that regex, it results in an infinite loop
error. So instead of using `DotPreconditions.checkArgument` to throw an
error, I made a check to see if the url is self referenced, and if it
true, then fallback to the main url.
**Note and question:** `final String urlIn =
!url.startsWith(StringPool.SLASH) ? StringPool.SLASH + url : url;` Was
added in the processForward function, this was because as navigating
through the UVE, the url that the backend gets doesn't have any starting
slashes, so in the case that the issue specifies, using `(.*)/index`
regex (and forwardTo $1) didn't match when navigating to index as the
url that the function receives would be `index` (without slash). So as
the `resolveVanityUrlIfPresent` does, this will try to check for matches
on the vanityUrl but with a `correctedUri` that will have a `/` at the
start. Before the addition of the slash and as the url didn't matched,
the forwardTo field remained on $1 and then we got the same error as the
problem 1. Adding the slash resulted in the problem 3, which was also
solved.
So the questions would be if this is ok. Should we handle it in a
different way? Could be some cases in where the addition of the slash
results in a wrong url or redirect?
### Checklist
- [x] Tests
---------
Co-authored-by: Jalinson Diaz <[email protected]>1 parent e754349 commit 697a045
File tree
16 files changed
+184
-72
lines changed- core-web/libs
- portlets/edit-ema/portlet/src/lib
- dot-ema-shell
- edit-ema-editor
- components/dot-uve-toolbar/components/dot-uve-workflow-actions
- services/guards
- store/features
- editor
- load
- utils
- sdk/client/src/lib/editor
- dotCMS/src/main/java/com/dotcms
- rest/api/v1/page
- vanityurl/model
- dotcms-integration/src/test/java/com/dotcms/rest/api/v1/page
16 files changed
+184
-72
lines changedLines changed: 13 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
332 | | - | |
| 332 | + | |
333 | 333 | | |
334 | | - | |
| 334 | + | |
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
345 | | - | |
| 345 | + | |
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
| |||
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
356 | | - | |
| 356 | + | |
357 | 357 | | |
358 | 358 | | |
359 | | - | |
| 359 | + | |
360 | 360 | | |
361 | 361 | | |
362 | 362 | | |
| |||
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
378 | | - | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
379 | 382 | | |
380 | | - | |
| 383 | + | |
381 | 384 | | |
382 | 385 | | |
383 | 386 | | |
| |||
392 | 395 | | |
393 | 396 | | |
394 | 397 | | |
395 | | - | |
| 398 | + | |
396 | 399 | | |
397 | 400 | | |
398 | 401 | | |
| |||
406 | 409 | | |
407 | 410 | | |
408 | 411 | | |
409 | | - | |
| 412 | + | |
410 | 413 | | |
411 | 414 | | |
412 | 415 | | |
| |||
657 | 660 | | |
658 | 661 | | |
659 | 662 | | |
660 | | - | |
| 663 | + | |
661 | 664 | | |
662 | 665 | | |
663 | 666 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
| 207 | + | |
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
373 | | - | |
| 373 | + | |
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
| |||
2589 | 2589 | | |
2590 | 2590 | | |
2591 | 2591 | | |
2592 | | - | |
| 2592 | + | |
2593 | 2593 | | |
2594 | 2594 | | |
2595 | 2595 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
| 39 | + | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
| 46 | + | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
247 | 253 | | |
248 | 254 | | |
249 | 255 | | |
250 | 256 | | |
251 | | - | |
| 257 | + | |
252 | 258 | | |
253 | 259 | | |
254 | 260 | | |
| |||
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
213 | | - | |
214 | | - | |
| 212 | + | |
215 | 213 | | |
216 | 214 | | |
217 | 215 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
86 | 85 | | |
87 | 86 | | |
88 | | - | |
| 87 | + | |
89 | 88 | | |
90 | 89 | | |
91 | 90 | | |
| |||
Lines changed: 14 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
200 | 202 | | |
201 | 203 | | |
202 | 204 | | |
203 | 205 | | |
204 | 206 | | |
205 | | - | |
206 | | - | |
207 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
208 | 212 | | |
209 | 213 | | |
210 | 214 | | |
| |||
292 | 296 | | |
293 | 297 | | |
294 | 298 | | |
295 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
296 | 303 | | |
297 | 304 | | |
298 | 305 | | |
| |||
633 | 640 | | |
634 | 641 | | |
635 | 642 | | |
636 | | - | |
637 | | - | |
| 643 | + | |
| 644 | + | |
638 | 645 | | |
639 | 646 | | |
640 | 647 | | |
| |||
Lines changed: 11 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
312 | | - | |
313 | | - | |
| 312 | + | |
| 313 | + | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
317 | | - | |
| 316 | + | |
| 317 | + | |
318 | 318 | | |
319 | 319 | | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
| 320 | + | |
| 321 | + | |
334 | 322 | | |
335 | 323 | | |
336 | 324 | | |
337 | 325 | | |
338 | | - | |
339 | | - | |
| 326 | + | |
| 327 | + | |
340 | 328 | | |
341 | 329 | | |
342 | 330 | | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
350 | 334 | | |
351 | 335 | | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | 336 | | |
357 | 337 | | |
358 | 338 | | |
| |||
0 commit comments