Skip to content

Commit 70b5389

Browse files
Merge branch 'master' into SNOW-1853185-JDBC-Driver-v3.16-Native-Okta-HTTP-Retry-Storm
2 parents 8977e89 + 32fa12c commit 70b5389

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

src/main/java/net/snowflake/client/core/SFBaseSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public abstract class SFBaseSession {
145145
private boolean enableExactSchemaSearch = false;
146146

147147
/** Disable lookup for default credentials by GCS library */
148-
private boolean disableGcsDefaultCredentials = false;
148+
private boolean disableGcsDefaultCredentials = true;
149149

150150
private Map<String, Object> commonParameters;
151151

src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import net.snowflake.client.log.ArgSupplier;
7171
import net.snowflake.client.log.SFLogger;
7272
import net.snowflake.client.log.SFLoggerFactory;
73+
import net.snowflake.client.util.SecretDetector;
7374
import net.snowflake.common.core.FileCompressionType;
7475
import net.snowflake.common.core.RemoteStoreFileEncryptionMaterial;
7576
import net.snowflake.common.core.SqlState;
@@ -1337,7 +1338,8 @@ private static JsonNode parseCommandInGS(SFStatement statement, String command)
13371338
}
13381339

13391340
JsonNode jsonNode = (JsonNode) result;
1340-
logger.debug("Response: {}", jsonNode.toString());
1341+
1342+
logger.debug("Response: {}", SecretDetector.maskSecrets(jsonNode.toString()));
13411343

13421344
SnowflakeUtil.checkErrorAndThrowException(jsonNode);
13431345
return jsonNode;

src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeGCSClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,8 +1372,7 @@ private static void overrideHost(StageInfo stage, StorageOptions.Builder builder
13721372

13731373
private static boolean areDisabledGcsDefaultCredentials(SFSession session) {
13741374
return session != null && session.getDisableGcsDefaultCredentials()
1375-
|| convertSystemPropertyToBooleanValue(
1376-
DISABLE_GCS_DEFAULT_CREDENTIALS_PROPERTY_NAME, false);
1375+
|| convertSystemPropertyToBooleanValue(DISABLE_GCS_DEFAULT_CREDENTIALS_PROPERTY_NAME, true);
13771376
}
13781377

13791378
private static boolean isSuccessStatusCode(int code) {

src/main/java/net/snowflake/client/util/SecretDetector.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public class SecretDetector {
7979
"(token|assertion content)" + "(['\"\\s:=]+)" + "([a-z0-9=/_\\-+]{8,})",
8080
Pattern.CASE_INSENSITIVE);
8181

82+
private static final Pattern ENCRYPTION_MATERIAL_PATTERN =
83+
Pattern.compile("\"encryptionMaterial\"\\s*:\\s*\\{.*?\\}", Pattern.CASE_INSENSITIVE);
84+
8285
// only attempt to find secrets in its leading 100Kb SNOW-30961
8386
private static final int MAX_LENGTH = 100 * 1000;
8487

@@ -222,7 +225,9 @@ public static String maskSASToken(String text) {
222225
public static String maskSecrets(String text) {
223226
return filterAccessTokens(
224227
filterConnectionTokens(
225-
filterPassword(filterSASTokens(filterAWSKeys(filterOAuthTokens(text))))));
228+
filterPassword(
229+
filterSASTokens(
230+
filterAWSKeys(filterOAuthTokens(filterEncryptionMaterial(text)))))));
226231
}
227232

228233
/**
@@ -283,6 +288,23 @@ public static String filterAccessTokens(String message) {
283288
return message;
284289
}
285290

291+
/**
292+
* Filter encryption material that may be buried inside a JSON string.
293+
*
294+
* @param message the message text which may contain encryption material
295+
* @return Return filtered message
296+
*/
297+
public static String filterEncryptionMaterial(String message) {
298+
Matcher matcher =
299+
ENCRYPTION_MATERIAL_PATTERN.matcher(
300+
message.length() <= MAX_LENGTH ? message : message.substring(0, MAX_LENGTH));
301+
302+
if (matcher.find()) {
303+
return matcher.replaceAll("\"encryptionMaterial\" : ****");
304+
}
305+
return message;
306+
}
307+
286308
public static JSONObject maskJsonObject(JSONObject json) {
287309
for (Map.Entry<String, Object> entry : json.entrySet()) {
288310
if (entry.getValue() instanceof String) {

src/test/java/net/snowflake/client/util/SecretDetectorTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,27 @@ public void testMaskJacksonObject() {
421421
"Nested Jackson array node is not masked successfully",
422422
maskedNestedArrayStr.equals(SecretDetector.maskJacksonNode(objNode4).toString()));
423423
}
424+
425+
@Test
426+
public void testEncryptionMaterialFilter() throws Exception {
427+
String messageText =
428+
"{\"data\":"
429+
+ "{\"autoCompress\":true,"
430+
+ "\"overwrite\":false,"
431+
+ "\"clientShowEncryptionParameter\":true,"
432+
+ "\"encryptionMaterial\":{\"queryStageMasterKey\":\"asdfasdfasdfasdf==\",\"queryId\":\"01b6f5ba-0002-0181-0000-11111111da\",\"smkId\":1111},"
433+
+ "\"stageInfo\":{\"locationType\":\"AZURE\", \"region\":\"eastus2\"}";
434+
435+
String filteredMessageText =
436+
"{\"data\":"
437+
+ "{\"autoCompress\":true,"
438+
+ "\"overwrite\":false,"
439+
+ "\"clientShowEncryptionParameter\":true,"
440+
+ "\"encryptionMaterial\" : ****,"
441+
+ "\"stageInfo\":{\"locationType\":\"AZURE\", \"region\":\"eastus2\"}";
442+
443+
String result = SecretDetector.filterEncryptionMaterial(messageText);
444+
445+
assertEquals(filteredMessageText, result);
446+
}
424447
}

0 commit comments

Comments
 (0)