Commit 066803a
committed
GROOVY-12271: Confine snippet file resolution to the snippet-files directory
{@snippet file="..."} took the file name verbatim from a doc comment and
joined it onto the package's snippet-files/ directory with no normalization
or containment check, so ../ segments escaped to anywhere the user running
groovydoc could read. JEP 413 confines javadoc's snippet resolution to
--snippet-path; the port added in GROOVY-11938 omitted the check.
This matters because it grants the author of documented source a capability
at doc time rather than at run time: a doc comment in a pull request can
read a file from the machine building the docs and publish its contents in
the rendered page.
Treat the file attribute as relative to snippet-files/, as JEP 413 does,
and confine resolution to that directory:
- an absolute name is refused outright, rather than accepted when it
happens to land inside the directory, so that a doc comment cannot
resolve on its author's machine and fail on a build agent;
- a relative name is normalized and required to stay inside;
- containment is re-checked after following symbolic links, so a link
within the directory cannot point out of it;
- an unusable name renders nothing instead of throwing.
Covered by two tests: one placing a file outside snippet-files/ and
referencing it relatively and absolutely, asserting its contents never
reach the rendered page; one referencing a file that genuinely is inside,
by both an absolute and a relative name, asserting only the relative form
resolves. Removing either guard fails the corresponding test.1 parent 389ab8c commit 066803a
2 files changed
Lines changed: 104 additions & 2 deletions
File tree
- subprojects/groovy-groovydoc/src
- main/java/org/codehaus/groovy/tools/groovydoc
- test/groovy/org/codehaus/groovy/tools/groovydoc
Lines changed: 45 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
477 | 478 | | |
478 | 479 | | |
479 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
480 | 487 | | |
481 | 488 | | |
482 | 489 | | |
| |||
488 | 495 | | |
489 | 496 | | |
490 | 497 | | |
491 | | - | |
492 | | - | |
| 498 | + | |
| 499 | + | |
493 | 500 | | |
494 | 501 | | |
495 | 502 | | |
| |||
501 | 508 | | |
502 | 509 | | |
503 | 510 | | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
504 | 547 | | |
505 | 548 | | |
506 | 549 | | |
| |||
Lines changed: 59 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
310 | 310 | | |
311 | 311 | | |
312 | 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 | + | |
313 | 372 | | |
314 | 373 | | |
315 | 374 | | |
| |||
0 commit comments