Commit 1321eaa
committed
GROOVY-12279: SecureASTCustomizer: apply import rules to a method pointer's target type
The indirect import check asked about a method pointer's own type. A
MethodPointerExpression fixes that to groovy.lang.Closure in its
constructor, so the check never concerned the class the pointer is taken
on, and its second argument was the whole expression text where
assertStaticImportIsAllowed expects a member name.
Both modes were wrong, in opposite directions. Measured with the check
enabled:
disallowedImports = [java.lang.ProcessBuilder]
new ProcessBuilder() blocked
ProcessBuilder.&new allowed
ProcessBuilder::new allowed
allowedImports = [java.util.ArrayList]
ArrayList.&size refused
The deny list missed the pointer entirely, since nothing names Closure in
one. The allow list refused every pointer, including pointers to a class it
allowed, because Closure is not in an allow list either. So the check both
let through what it was meant to stop and stopped what it was meant to
allow.
Ask about the class the pointer is taken on, unwrapping arrays through the
same helper the method call branch uses, and pass the method name rather
than the expression text.
This changes behaviour in both directions, each toward what the flag
documents: a denied target is now refused, and a pointer to an allowed
target is now permitted where it was refused before.
An existing assertion covered java.util.LinkedList.&size under an allow
list, and passed only because Closure was absent from that list; it passes
after this change too, now for the reason it appears to be testing.1 parent 55dcfb9 commit 1321eaa
2 files changed
Lines changed: 43 additions & 2 deletions
File tree
- src
- main/java/org/codehaus/groovy/control/customizers
- test/groovy/org/codehaus/groovy/control/customizers
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1508 | 1508 | | |
1509 | 1509 | | |
1510 | 1510 | | |
1511 | | - | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
1512 | 1515 | | |
1513 | | - | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
1514 | 1519 | | |
1515 | 1520 | | |
1516 | 1521 | | |
| |||
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 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 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
339 | 375 | | |
340 | 376 | | |
341 | 377 | | |
| |||
0 commit comments