G
Gulnar78
Guest
How Can I avoid Directory traversal in the following function underlined lines?
public byte[] GetFile(string filePath) {
if (filePath == null) throw new ArgumentNullException(nameof(filePath));
try {
switch (StorageProtocol) {
case "SMB":
case "Local":
using (new NetworkConnection(StoragePath, StorageCredential)) {
return File.ReadAllBytes($"{StoragePath}/{filePath}");
}
case "IIS":
return File.ReadAllBytes(HttpContext.Current.Server.MapPath($"~/Files/{filePath}"));
}
-----------------------
public static void wordFillBookmarks(List<KeyValuePair<string, string>> keyValues, string docPath, string destinationPath) {
File.Copy(docPath, destinationPath, true);
Package package = Package.Open(destinationPath, FileMode.Open, FileAccess.ReadWrite);
----------------------
public static void ...............{
formStream = new MemoryStream();
using (var templateStream = File.OpenRead(templatePath))
Regards,
Continue reading...
public byte[] GetFile(string filePath) {
if (filePath == null) throw new ArgumentNullException(nameof(filePath));
try {
switch (StorageProtocol) {
case "SMB":
case "Local":
using (new NetworkConnection(StoragePath, StorageCredential)) {
return File.ReadAllBytes($"{StoragePath}/{filePath}");
}
case "IIS":
return File.ReadAllBytes(HttpContext.Current.Server.MapPath($"~/Files/{filePath}"));
}
-----------------------
public static void wordFillBookmarks(List<KeyValuePair<string, string>> keyValues, string docPath, string destinationPath) {
File.Copy(docPath, destinationPath, true);
Package package = Package.Open(destinationPath, FileMode.Open, FileAccess.ReadWrite);
----------------------
public static void ...............{
formStream = new MemoryStream();
using (var templateStream = File.OpenRead(templatePath))
Regards,
Continue reading...