Skip to content

Commit 4465526

Browse files
fix(iot-dev): Add an upper limit to SAS token expiry time values (#1755)
A recent customer issue revealed that very high values for this field result in the SDK repeatedly sending new SAS tokens due to an integer overflow
1 parent d547e53 commit 4465526

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/ClientConfiguration.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public final class ClientConfiguration
4646

4747
private static final long DEFAULT_OPERATION_TIMEOUT = 4 * 60 * 1000; //4 minutes
4848

49+
private static final long MAX_SAS_TOKEN_EXPIRY_TIME_SECONDS = 10 * 365 * 24 * 60 * 60; //10 years
50+
4951
private boolean useWebsocket;
5052

5153
@Getter
@@ -244,6 +246,13 @@ private void setClientOptionValues(ClientOptions clientOptions)
244246
throw new IllegalArgumentException("ClientOption sasTokenExpiryTime must be greater than 0");
245247
}
246248

249+
if (clientOptions.getSasTokenExpiryTime() >= MAX_SAS_TOKEN_EXPIRY_TIME_SECONDS)
250+
{
251+
// Higher values cause overflows that result in the SDK repeatedly renewing SAS tokens
252+
// and are generally a security risk
253+
throw new IllegalArgumentException("ClientOption sasTokenExpiryTime must be less than 10 years");
254+
}
255+
247256
this.getSasTokenAuthentication().setTokenValidSecs(clientOptions.getSasTokenExpiryTime());
248257
}
249258

0 commit comments

Comments
 (0)