-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
54 additions
and
6 deletions.
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
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
37 changes: 37 additions & 0 deletions
37
src/zipstream/http/server/handlers/symlink_static_file_handler.cr
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,37 @@ | ||
module Zipstream | ||
class SymlinkStaticFileHandler | ||
include HTTP::Handler | ||
|
||
property config | ||
|
||
def initialize(@config : Config) | ||
end | ||
|
||
def call(context) | ||
if config.no_symlinks? && contains_symlink_in_parent_directory?(config.path, context.request.path.chomp('/')) | ||
context.response.respond_with_status(:not_found) | ||
|
||
return | ||
end | ||
|
||
call_next(context) | ||
end | ||
|
||
# Check if any parent directory within the base path contains a symlink | ||
private def contains_symlink_in_parent_directory?(base_path, relative_path) | ||
path = File.join(base_path, relative_path) | ||
|
||
loop do | ||
return true if File.symlink?(path) | ||
|
||
parent_directory = File.dirname(path) | ||
|
||
break if parent_directory == path || parent_directory == base_path | ||
|
||
path = parent_directory | ||
end | ||
|
||
false | ||
end | ||
end | ||
end |
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