From c5c8c79b113c3c2ff6b020151d5c1e94276c7d0c Mon Sep 17 00:00:00 2001 From: Christoph Kulla <137039388+ckullabosch@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:31:42 +0200 Subject: [PATCH 1/4] [JENKINS-72975] Permit java.util.regex.MatchResult.group(String) --- .../plugins/scriptsecurity/sandbox/whitelists/generic-whitelist | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist b/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist index 26b77a78d..252c671f6 100644 --- a/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist +++ b/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist @@ -792,6 +792,7 @@ method java.util.regex.MatchResult end method java.util.regex.MatchResult end int method java.util.regex.MatchResult group method java.util.regex.MatchResult group int +method java.util.regex.MatchResult group java.lang.String method java.util.regex.MatchResult groupCount method java.util.regex.MatchResult start method java.util.regex.MatchResult start int From e1fe2bd1d8bfcf61b97419f61e5d8876872180ce Mon Sep 17 00:00:00 2001 From: Christoph Kulla <137039388+ckullabosch@users.noreply.github.com> Date: Mon, 8 Apr 2024 08:21:01 +0000 Subject: [PATCH 2/4] Add additional methods of MatchResult --- .../sandbox/whitelists/generic-whitelist | 4 ++++ .../sandbox/whitelists/StaticWhitelistTest.java | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist b/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist index 252c671f6..cb990da47 100644 --- a/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist +++ b/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist @@ -790,12 +790,16 @@ method java.util.random.RandomGenerator nextInt int method java.util.random.RandomGenerator nextLong method java.util.regex.MatchResult end method java.util.regex.MatchResult end int +method java.util.regex.MatchResult end java.lang.String method java.util.regex.MatchResult group method java.util.regex.MatchResult group int method java.util.regex.MatchResult group java.lang.String method java.util.regex.MatchResult groupCount +method java.util.regex.MatchResult hasMatch +method java.util.regex.MatchResult namedGroups method java.util.regex.MatchResult start method java.util.regex.MatchResult start int +method java.util.regex.MatchResult start java.lang.String method java.util.regex.Matcher appendReplacement java.lang.StringBuffer java.lang.String method java.util.regex.Matcher appendTail java.lang.StringBuffer method java.util.regex.Matcher end java.lang.String diff --git a/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java b/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java index b32b8728e..ac87112a7 100644 --- a/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java +++ b/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java @@ -41,6 +41,7 @@ import java.util.Random; import java.util.Set; import java.util.regex.Matcher; +import java.util.regex.MatchResult; import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.EnumeratingWhitelist.MethodSignature; import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.EnumeratingWhitelist.Signature; @@ -145,7 +146,14 @@ static void sanity(URL definition) throws Exception { // Override the corresponding MatchResult methods in Java 20+. new MethodSignature(Matcher.class, "end", String.class), new MethodSignature(Matcher.class, "group", String.class), - new MethodSignature(Matcher.class, "start", String.class) + new MethodSignature(Matcher.class, "start", String.class), + // Override MatchResult default methods in Java 20+ (for Java 17 compatibility) + new MethodSignature(MatchResult.class, "end", String.class), + new MethodSignature(MatchResult.class, "group", String.class), + new MethodSignature(MatchResult.class, "hasMatch"), + new MethodSignature(MatchResult.class, "namedGroups"), + new MethodSignature(MatchResult.class, "start", String.class), + )); @Test public void sanity() throws Exception { From 1d6bf8497e2caab0ba155d1611828842837588ee Mon Sep 17 00:00:00 2001 From: Christoph Kulla <137039388+ckullabosch@users.noreply.github.com> Date: Mon, 8 Apr 2024 08:32:02 +0000 Subject: [PATCH 3/4] Fix syntax --- .../scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java b/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java index ac87112a7..83523ff64 100644 --- a/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java +++ b/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java @@ -152,8 +152,7 @@ static void sanity(URL definition) throws Exception { new MethodSignature(MatchResult.class, "group", String.class), new MethodSignature(MatchResult.class, "hasMatch"), new MethodSignature(MatchResult.class, "namedGroups"), - new MethodSignature(MatchResult.class, "start", String.class), - + new MethodSignature(MatchResult.class, "start", String.class) )); @Test public void sanity() throws Exception { From 75aeede54db8d3c312e61af25520ce3b715e24dd Mon Sep 17 00:00:00 2001 From: Devin Nusbaum Date: Mon, 8 Apr 2024 10:17:37 -0400 Subject: [PATCH 4/4] [JENKINS-72975] Update comment for new known good signatures in tests --- .../scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java b/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java index 83523ff64..c705694a7 100644 --- a/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java +++ b/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java @@ -147,7 +147,7 @@ static void sanity(URL definition) throws Exception { new MethodSignature(Matcher.class, "end", String.class), new MethodSignature(Matcher.class, "group", String.class), new MethodSignature(Matcher.class, "start", String.class), - // Override MatchResult default methods in Java 20+ (for Java 17 compatibility) + // Do not exist until Java 20. new MethodSignature(MatchResult.class, "end", String.class), new MethodSignature(MatchResult.class, "group", String.class), new MethodSignature(MatchResult.class, "hasMatch"),