-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sanitize user input #187
Closed
Closed
Sanitize user input #187
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d9072d1
Remove obsolete Docker-Compose version tag
flenny 2d44e45
Sanitize user input
flenny 832dca1
Encode user input in log entries
flenny 83a4424
Sanitize user input in FileProvider
flenny 42d4fb2
Sanitize user input in FileProvider
flenny 6dfacf2
Sanitize user input in FileProvider
flenny 098f573
Sanitize user input in FileProvider
flenny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
version: "3.4" | ||
|
||
services: | ||
stac-browser: | ||
image: ghcr.io/geowerkstatt/stac-browser:latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace Geopilot.Api; | ||
|
||
/// <summary> | ||
/// GeoPilot API extensions. | ||
/// </summary> | ||
public static class Extensions | ||
{ | ||
/// <summary> | ||
/// Sanitizes a file name by removing invalid characters. | ||
/// </summary> | ||
/// <param name="fileName">The file name to sanitize.</param> | ||
/// <returns>The sanitized file name.</returns> | ||
public static string SanitizeFileName(this string fileName) | ||
{ | ||
// Get invalid characters for file names and add some platform-specific ones. | ||
var invalidFileNameChars = Path.GetInvalidFileNameChars() | ||
.Concat(new[] { '?', '$', '*', '|', '<', '>', '"', ':' }).ToArray(); | ||
|
||
return new string(fileName | ||
.Trim() | ||
.ReplaceLineEndings(string.Empty) | ||
.Replace("..", string.Empty) | ||
.Replace("./", string.Empty) | ||
.Where(x => !invalidFileNameChars.Contains(x)).ToArray()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace Geopilot.Api.Controllers; | ||
|
||
[TestClass] | ||
public class Extensions | ||
{ | ||
[TestMethod] | ||
public void SanitizeFileNameForValidFileNames() | ||
{ | ||
AssertSanitizeFileName("SQUIRRELGENESIS", "SQUIRRELGENESIS"); | ||
AssertSanitizeFileName("JUNIORARK.xyz", "JUNIORARK.xyz"); | ||
AssertSanitizeFileName("PEEVEDBEAM-ANT.MESS.abc", "PEEVEDBEAM-ANT.MESS.abc"); | ||
AssertSanitizeFileName("WEIRD WATER.example", "WEIRD WATER.example"); | ||
AssertSanitizeFileName("AUTOFIRE123.doc", "AUTOFIRE123.doc"); | ||
AssertSanitizeFileName("SUNNY(1).doc", "SUNNY(1).doc"); | ||
AssertSanitizeFileName("ODD_MONKEY.doc", "ODD_MONKEY.doc"); | ||
AssertSanitizeFileName("SILLY,MONKEY.docx", "SILLY,MONKEY.docx"); | ||
AssertSanitizeFileName("CamelCase.bat", "CamelCase.bat"); | ||
AssertSanitizeFileName("SLICKER-CHIPMUNK.bat", "SLICKER-CHIPMUNK.bat"); | ||
} | ||
|
||
[TestMethod] | ||
public void SanitizeFileNameForInvalidFileNames() | ||
{ | ||
AssertSanitizeFileName("CHIPMUNKWALK", " CHIPMUNKWALK "); | ||
AssertSanitizeFileName("SLEEPYBOUNCE", "SLEEPYBOUNCE\n"); | ||
AssertSanitizeFileName("PLOWARK", "PLOWARK\r"); | ||
AssertSanitizeFileName("JUNIORGLEE", "JUNIORGLEE\t"); | ||
AssertSanitizeFileName("SILLYWATER", "SILLYWATER\r\n"); | ||
AssertSanitizeFileName("LATENTROUTE34", "LATENTROUTE?34"); | ||
AssertSanitizeFileName("TRAWLSOUFFLE", "/TRAWLSOUFFLE*"); | ||
AssertSanitizeFileName("VIOLENTIRON", "><VIOLENTIRON\"|"); | ||
AssertSanitizeFileName("YELLOWBAGEL", "YELLOWBAGEL://"); | ||
AssertSanitizeFileName("ZANYWATER", "ZANYWATER$"); | ||
AssertSanitizeFileName("SLICKERCANDID", "..\\SLICKERCANDID"); | ||
AssertSanitizeFileName("DIREFOOT", "./DIREFOOT:"); | ||
} | ||
|
||
private static void AssertSanitizeFileName(string expected, string fileName) | ||
=> Assert.AreEqual(expected, fileName.SanitizeFileName()); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PP: Umbenenn zu
StringExtensions
, da diese Klasse genau das beinhaltet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Danke! Wartet bitte noch mit dem Review... ich schliesse diesen hier wieder 😅