From 4b059c4fa730b419fdf4d6745bb6cd70390a5412 Mon Sep 17 00:00:00 2001 From: hidingmyname Date: Tue, 3 Nov 2026 15:48:06 +0800 Subject: [PATCH] services: Reject wildcards and options in binary log exclusions gRFC A16 says an exclusion is "-/": "*" must not be used for negations, and a malformed pattern must be rejected. FactoryImpl checked for a service glob before it checked for a leading "-", so "-p.s/*" became a per-service log for a service named "-p.s" and no exclusion was recorded. With "*,-p.s/*", p.s was still logged. "-*" was stored as an exclusion for a method named "*", and the "{h}" in "-p.s/m{h}" was silently dropped. Reject an exclusion that contains "*" or has a {...} suffix with the same "Illegal log config pattern" error as other malformed patterns, as grpc-go does. Fixes #13155 --- .../java/io/grpc/protobuf/services/BinlogHelper.java | 5 +++++ .../io/grpc/protobuf/services/BinlogHelperTest.java | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/services/src/main/java/io/grpc/protobuf/services/BinlogHelper.java b/services/src/main/java/io/grpc/protobuf/services/BinlogHelper.java index e810c983beb..ec8721f1211 100644 --- a/services/src/main/java/io/grpc/protobuf/services/BinlogHelper.java +++ b/services/src/main/java/io/grpc/protobuf/services/BinlogHelper.java @@ -635,6 +635,11 @@ static final class FactoryImpl implements Factory { if (methodOrSvc.isEmpty()) { throw new IllegalArgumentException("Illegal log config pattern: " + configuration); } + if (methodOrSvc.startsWith("-") + && (binlogOptionStr != null || methodOrSvc.contains("*"))) { + // An exclusion names exactly one method; '*' and '{...}' are not allowed + throw new IllegalArgumentException("Illegal log config pattern: " + configuration); + } if (methodOrSvc.equals("*")) { // parse config for "*" checkState( diff --git a/services/src/test/java/io/grpc/protobuf/services/BinlogHelperTest.java b/services/src/test/java/io/grpc/protobuf/services/BinlogHelperTest.java index ca42c1691b1..f4d1286a735 100644 --- a/services/src/test/java/io/grpc/protobuf/services/BinlogHelperTest.java +++ b/services/src/test/java/io/grpc/protobuf/services/BinlogHelperTest.java @@ -341,6 +341,18 @@ public void configBinLog_blacklist() { assertNotNull(makeLog("-p.s/blacklisted,p.s/*", "p.s/allowed")); } + @Test + public void configBinLog_blacklist_wildcardOrOptionsRejected() { + for (String configStr : new String[] {"*,-p.s/*", "-p.s/*", "-*", "-p.s/m{h}"}) { + try { + new FactoryImpl(sink, configStr); + fail("Expected IllegalArgumentException for " + configStr); + } catch (IllegalArgumentException expected) { + assertThat(expected).hasMessageThat().startsWith("Illegal log config pattern"); + } + } + } + private void assertDuplicatelPatternDetected(String factoryConfigStr) { try { new BinlogHelper.FactoryImpl(sink, factoryConfigStr);