This repository was archived by the owner on Jun 12, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 10
10
#include < fstream>
11
11
#include < boost/filesystem.hpp>
12
12
#include < array>
13
+ #include < algorithm>
13
14
14
15
using namespace std ;
15
16
// Added for the json-example:
@@ -85,12 +86,14 @@ int main() {
85
86
// Default file: index.html
86
87
// Can for instance be used to retrieve an HTML 5 client that uses REST-resources on this server
87
88
server.default_resource [" GET" ]=[](HttpServer::Response& response, shared_ptr<HttpServer::Request> request) {
88
- string web_root_path=boost::filesystem::canonical (" web" ). string ( );
89
+ const auto web_root_path=boost::filesystem::canonical (" web" );
89
90
boost::filesystem::path path=web_root_path;
90
91
path/=request->path ;
91
92
if (boost::filesystem::exists (path)) {
92
- auto path_str=boost::filesystem::canonical (path).string ();
93
- if (path_str.substr (0 , web_root_path.size ())==web_root_path) {
93
+ path=boost::filesystem::canonical (path);
94
+ // Check if path is within web_root_path
95
+ if (distance (web_root_path.begin (), web_root_path.end ())<=distance (path.begin (), path.end ()) &&
96
+ equal (web_root_path.begin (), web_root_path.end (), path.begin ())) {
94
97
if (boost::filesystem::is_directory (path))
95
98
path/=" index.html" ;
96
99
if (boost::filesystem::exists (path) && boost::filesystem::is_regular_file (path)) {
Original file line number Diff line number Diff line change 10
10
#include < fstream>
11
11
#include < boost/filesystem.hpp>
12
12
#include < array>
13
+ #include < algorithm>
13
14
14
15
using namespace std ;
15
16
// Added for the json-example:
@@ -85,12 +86,14 @@ int main() {
85
86
// Default file: index.html
86
87
// Can for instance be used to retrieve an HTML 5 client that uses REST-resources on this server
87
88
server.default_resource [" GET" ]=[](HttpsServer::Response& response, shared_ptr<HttpsServer::Request> request) {
88
- string web_root_path=boost::filesystem::canonical (" web" ). string ( );
89
+ const auto web_root_path=boost::filesystem::canonical (" web" );
89
90
boost::filesystem::path path=web_root_path;
90
91
path/=request->path ;
91
92
if (boost::filesystem::exists (path)) {
92
- auto path_str=boost::filesystem::canonical (path).string ();
93
- if (path_str.substr (0 , web_root_path.size ())==web_root_path) {
93
+ path=boost::filesystem::canonical (path);
94
+ // Check if path is within web_root_path
95
+ if (distance (web_root_path.begin (), web_root_path.end ())<=distance (path.begin (), path.end ()) &&
96
+ equal (web_root_path.begin (), web_root_path.end (), path.begin ())) {
94
97
if (boost::filesystem::is_directory (path))
95
98
path/=" index.html" ;
96
99
if (boost::filesystem::exists (path) && boost::filesystem::is_regular_file (path)) {
You can’t perform that action at this time.
0 commit comments