I am trying to create a Regular Expression for validation to stop directory traversal attacks. I want the user to be able to specify anything within the C:\temp directory. So the below is fine
c:\temp\hello\world.txt
but obviously, the directory below would be unacceptable.
c:\temp\..\Windows\world.txt
My issue is that I am unsure how I can allow one period (.) but not two in a row. I need one obviously for extensions i.e. (world.txt) but can not have two. This is what I have so far:
^([c]:\\)\\?(temp)([^(\.\.)]){0,200}$
So I am trying to say not two periods [^\.\.] and the \\? part is because it accepts escaped directories as well. Thanks in advance.