Skip to content

Commit c5c6ae1

Browse files
committed
Validate region name is within allowed names
This is required because RegionEndpoint.GetBySystemName() returns `unknown` instead of throwing.
1 parent e9896fa commit c5c6ae1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/ServiceControl.Transports.SQS/AmazonSQSQuery.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,15 @@ protected override void InitializeCore(ReadOnlyDictionary<string, string> settin
9292
}
9393
}
9494

95+
bool IsValidAwsRegion(string region) => RegionEndpoint.EnumerableAllRegions.Any(r => r.SystemName.Equals(region, StringComparison.OrdinalIgnoreCase));
96+
9597
if (settings.TryGetValue(AmazonSQSSettings.Region, out string? region))
9698
{
9799
string? previousSetSystemName = regionEndpoint?.SystemName;
100+
if (!IsValidAwsRegion(region))
101+
{
102+
throw new ArgumentException("Invalid region endpoint provided");
103+
}
98104
regionEndpoint = RegionEndpoint.GetBySystemName(region);
99105

100106
Diagnostics.Append($"Region set to \"{regionEndpoint.SystemName}\"");
@@ -109,6 +115,10 @@ protected override void InitializeCore(ReadOnlyDictionary<string, string> settin
109115
{
110116
if (sqsConnectionString.Region != null)
111117
{
118+
if (!IsValidAwsRegion(sqsConnectionString.Region))
119+
{
120+
throw new ArgumentException("Invalid region endpoint provided");
121+
}
112122
regionEndpoint = RegionEndpoint.GetBySystemName(sqsConnectionString.Region);
113123
Diagnostics.AppendLine(
114124
$"Region not set, defaulted to using \"{regionEndpoint.SystemName}\" from the ConnectionString used by instance");

0 commit comments

Comments
 (0)