Assume some intranet WebAPI endpoint like:
public class AttachmentDto
{
public String Path { get; set; }
}
public class AttachmentsApiController : ApiController
{
public void Post(AttachmentDto attachment)
{
var attachmentsStorage = new AttachmentsStorage();
attachmentsStorage.Add(attachment.Path);
}
}
where AttachmentsStorage
in one or another way reads the file at attachment.Path
(one or another network share) and saves the contents at some more or less publicly available and known place.
That is basically equivalent to simply
public String Post(AttachmentDto attachment)
{
return File.ReadAllText(attachment.Path);
}
That in my opinion evaluates to security vulnerability, even though the system is intranet, because any file on the server that is accessible to the used service account can be technically read.
Am I correct?
If it is so, then what can be done to mitigate this issue?
I've considered:
- Pass the file contents - possible, though not desired for this particular system because of the assumed design and possible size of the files.
Prohibit any addresses that are not network shares. Something like:
private Boolean IsNetworkShareFile(String path) { var uri = new Uri(path); return uri.IsFile && uri.IsUnc && uri.IsAbsoluteUri; }
It seems to work, but it at best prevents only local file access(though some file share can actually point to local) and doesn't restrict access to private shares.
- Try impersonation/delegation - probably the best solution with
authentication mode="Windows"
, though it will require changing account settings in Active Directory