Skip to content

Commit 25137d9

Browse files
committed
SEBWIN-972: Ensured that also the server API endpoint is correctly sanitized.
1 parent 91ff724 commit 25137d9

6 files changed

Lines changed: 19 additions & 13 deletions

File tree

SafeExamBrowser.Configuration/ConfigurationData/DataMapping/ServerDataMapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ private void MapConfiguration(AppSettings settings, object value)
5151
{
5252
if (value is IDictionary<string, object> configuration)
5353
{
54-
if (configuration.TryGetValue(Keys.Server.ApiUrl, out var v) && v is string url)
54+
if (configuration.TryGetValue(Keys.Server.ApiEndpoint, out var v) && v is string endpoint)
5555
{
56-
settings.Server.ApiUrl = url;
56+
settings.Server.ApiEndpoint = endpoint;
5757
}
5858

5959
if (configuration.TryGetValue(Keys.Server.ClientName, out v) && v is string name)

SafeExamBrowser.Configuration/ConfigurationData/Keys.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ internal static class Security
277277

278278
internal static class Server
279279
{
280-
internal const string ApiUrl = "apiDiscovery";
280+
internal const string ApiEndpoint = "apiDiscovery";
281281
internal const string ClientName = "clientName";
282282
internal const string ClientSecret = "clientSecret";
283283
internal const string Configuration = "sebServerConfiguration";

SafeExamBrowser.Server/Requests/ApiRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal ApiRequest(
3030

3131
internal bool TryExecute(out Api api, out string message)
3232
{
33-
var success = TryExecute(HttpMethod.Get, settings.ApiUrl, out var response);
33+
var success = TryExecute(HttpMethod.Get, settings.ApiEndpoint, out var response);
3434

3535
api = new Api();
3636
message = response.ToLogString();

SafeExamBrowser.Server/Sanitizer.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ namespace SafeExamBrowser.Server
1414
{
1515
internal class Sanitizer
1616
{
17-
internal Uri Sanitize(string serverUrl)
18-
{
19-
return new Uri(serverUrl.EndsWith("/") ? serverUrl : $"{serverUrl}/");
20-
}
21-
2217
internal void Sanitize(Api api)
2318
{
2419
foreach (var property in api.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
@@ -29,5 +24,15 @@ internal void Sanitize(Api api)
2924
property.SetValue(api, sanitized);
3025
}
3126
}
27+
28+
internal Uri SanitizeBaseAddress(string serverUrl)
29+
{
30+
return new Uri(serverUrl.EndsWith("/") ? serverUrl : $"{serverUrl}/");
31+
}
32+
33+
internal string SanitizeApiEndpoint(string apiEndpoint)
34+
{
35+
return apiEndpoint.TrimStart('/');
36+
}
3237
}
3338
}

SafeExamBrowser.Server/ServerProxy.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,10 @@ public ConnectionInfo GetConnectionInfo()
204204
public void Initialize(ServerSettings settings)
205205
{
206206
this.settings = settings;
207+
this.settings.ApiEndpoint = sanitizer.SanitizeApiEndpoint(settings.ApiEndpoint);
207208

208209
httpClient = new HttpClient();
209-
httpClient.BaseAddress = sanitizer.Sanitize(settings.ServerUrl);
210+
httpClient.BaseAddress = sanitizer.SanitizeBaseAddress(settings.ServerUrl);
210211

211212
if (settings.RequestTimeout > 0)
212213
{

SafeExamBrowser.Settings/Server/ServerSettings.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ namespace SafeExamBrowser.Settings.Server
1717
public class ServerSettings
1818
{
1919
/// <summary>
20-
/// The discovery URL for the API of the server.
20+
/// The discovery endpoint for the API of the server.
2121
/// </summary>
22-
public string ApiUrl { get; set; }
22+
public string ApiEndpoint { get; set; }
2323

2424
/// <summary>
2525
/// The client name for initial authentication with the server.
@@ -77,7 +77,7 @@ public class ServerSettings
7777
public int RequestTimeout { get; set; }
7878

7979
/// <summary>
80-
/// The URL of the server.
80+
/// The base address of the server.
8181
/// </summary>
8282
public string ServerUrl { get; set; }
8383

0 commit comments

Comments
 (0)