Skip to content

Commit e777396

Browse files
committed
deprecate local_file -> resolve_path
1 parent f9505ab commit e777396

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

Experimental/Template.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ open Types
107107
/// write the exception as a string to a 500 Internal Error response.
108108
let process_template (data : Map<string,Binder>) ({ request = http_request; runtime = runtime } as ctx : HttpContext) =
109109
try
110-
let xmlReader = new XmlTextReader(Files.local_file http_request.url runtime.home_directory)
110+
let xmlReader = new XmlTextReader(Files.resolve_path runtime.home_directory http_request.url)
111111
xmlReader.Namespaces <- false
112112

113113
let transform = parser xmlReader (Xml [])

Suave/Http.fs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ module Http =
468468
(Path.GetExtension)
469469
send_file
470470

471-
let local_file (file_name : string) (root_path : string) =
471+
let resolve_path (root_path : string) (file_name : string) =
472472
let file_name =
473473
if Path.DirectorySeparatorChar.Equals('/') then file_name
474474
else file_name.Replace('/', Path.DirectorySeparatorChar)
@@ -479,9 +479,12 @@ module Http =
479479
else raise <| Exception("File canonalization issue.")
480480
else raise <| Exception("File canonalization issue.")
481481

482+
[<Obsolete("Use resolve_path")>]
483+
let local_file file_name root_path = resolve_path root_path file_name
484+
482485
let browse_file root_path file_name =
483486
fun ({request = r; runtime = q} as h) ->
484-
file (local_file file_name root_path) h
487+
file (resolve_path root_path file_name) h
485488

486489
let browse_file' file_name =
487490
fun ({request = r; runtime = q} as h) ->
@@ -494,7 +497,7 @@ module Http =
494497
Log.TraceHeader.empty
495498
(sprintf "Files.browse trying file (local_file url:'%s' root:'%s')"
496499
r.url root_path)
497-
file (local_file r.url root_path))
500+
file (resolve_path root_path r.url))
498501

499502
let browse' : WebPart =
500503
warbler (fun { runtime = q } -> browse q.home_directory)
@@ -504,7 +507,7 @@ module Http =
504507

505508
let url = req.url
506509

507-
let dirname = local_file url root_path
510+
let dirname = resolve_path root_path url
508511
let result = new StringBuilder()
509512

510513
let filesize (x : FileSystemInfo) =

Suave/Http.fsi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,11 @@ module Http =
13411341
/// <remarks>
13421342
/// The current implementation doesn't take kindly to relative paths.
13431343
/// </remarks>
1344+
val resolve_path : root_path:string -> file_name:string -> string
1345+
1346+
/// Deprecated: use `resolve_path` and swap the arguments' positions. It
1347+
/// has been deprecated so that you can curry the root_path in your function
1348+
/// scope, with the root path.
13441349
val local_file : file_name:string -> root_path:string -> string
13451350

13461351
/// <summary><para>

Tests/HttpFile.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let ``canonicalization attacks`` =
1717
testCase "should throw" <| fun _ ->
1818
Assert.Raise("'../../passwd' is not a valid path",
1919
typeof<Exception>,
20-
fun _ -> Files.local_file "../../passwd" current_path |> ignore)
20+
fun _ -> Files.resolve_path current_path "../../passwd" |> ignore)
2121
]
2222

2323
[<Tests>]

0 commit comments

Comments
 (0)