Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure JSON files pushed by client via DataHub include the .json extension #106

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading