directory listings are now properly URL encoded

This commit is contained in:
stryan 2020-06-09 12:16:12 -04:00
parent cfd26f4b23
commit f1d01ae465
2 changed files with 6 additions and 2 deletions

View File

@ -107,7 +107,7 @@ func generateDirectory(path string) Response {
//Found an index file, return that instead
return generateFile(path + file.Name())
} else {
dirpage += fmt.Sprintf("=> %s %s\r\n", file.Name(), file.Name())
dirpage += fmt.Sprintf("=> %s %s\r\n", url.PathEscape(file.Name()), file.Name())
}
}
return Response{STATUS_SUCCESS, "text/gemini", dirpage}

View File

@ -189,7 +189,11 @@ func (s *Server) ParseRequest(req string, c *conn) Response {
//now check cert stuff
capsule := s.HostnameToConfig[u.Hostname()]
selector := capsule.RootDir + u.Path
unescaped_path, err := url.PathUnescape(u.Path)
if err != nil {
return Response{STATUS_BAD_REQUEST, "URL invalid", ""}
}
selector := capsule.RootDir + unescaped_path
for _, idpath := range capsule.AccessControl.Identified {
if strings.Contains(selector, capsule.RootDir+idpath) && c.Cert == nil {
return Response{STATUS_CLIENT_CERTIFICATE_REQUIRED, "Please provide a client certificate", ""}