Skip to content

Commit

Permalink
Merge pull request #106 from GridProtectionAlliance/datahub-json-exte…
Browse files Browse the repository at this point in the history
…nsion

Ensure JSON files pushed by client via DataHub include the .json extension
  • Loading branch information
clackner-gpa authored Nov 25, 2024
2 parents 70293e4 + e2fb93d commit c2e925c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Source/Applications/openHistorian/openHistorian/DataHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,11 @@ public bool CheckIfUpdateCOMTRADECountersIsCompleted(uint operationHandle) =>
/// </summary>
/// <param name="targetFilePath">Target directory or file path for JSON file.</param>
/// <param name="json">JSON file content.</param>
/// <exception cref="SecurityException">Cannot save JSON file outside local file path.</exception>
/// <exception cref="SecurityException">
/// <para>Cannot save JSON file outside local file path.</para>
/// <para>OR</para>
/// <para>Cannot save JSON files without the .json extension.</para>
/// </exception>
/// <returns>URL to download filename.</returns>
public string SaveJSONFile(string targetFilePath, string json)
{
Expand All @@ -1282,6 +1286,10 @@ public string SaveJSONFile(string targetFilePath, string json)
if (string.IsNullOrEmpty(Path.GetFileName(targetFilePath)) || string.IsNullOrEmpty(Path.GetExtension(targetFilePath)))
targetFilePath = Path.Combine(targetFilePath, $"{DateTime.Now:s}Merge.json".Replace(':', '.'));

// Prevent saving files that are not given the .json file extension (helps prevent possible function abuse)
if (!string.Equals(Path.GetExtension(targetFilePath), ".json", StringComparison.InvariantCultureIgnoreCase))
throw new SecurityException("File type error: Cannot save JSON files without the .json extension.");

string directory = Path.GetDirectoryName(targetFilePath);

if (!Directory.Exists(directory))
Expand Down

0 comments on commit c2e925c

Please sign in to comment.