Skip to content

Commit e421a0c

Browse files
committed
add whitelist for dashboard static files to http server
1 parent 4acf184 commit e421a0c

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

pc/user.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,33 @@ void user::parse_content( const char *, size_t )
7575
{
7676
str path;
7777
hsvr_.get_path( path );
78+
79+
http_response msg;
80+
81+
// whitelist
82+
std::string const relpath{ path.str_, path.len_ };
83+
if (
84+
relpath != "/"
85+
&& relpath != "/dashboard.js"
86+
&& relpath != "/index.html"
87+
&& relpath != "/style.css"
88+
) {
89+
msg.init( "404", "Not Found" );
90+
msg.commit();
91+
add_send( msg );
92+
return;
93+
}
94+
7895
std::string cfile = sptr_->get_content_dir();
7996
if ( cfile.empty() ) {
8097
cfile += ".";
8198
}
82-
cfile += std::string( path.str_, path.len_ );
83-
if ( path == str( "/" ) ) {
99+
cfile += relpath;
100+
if ( relpath == "/" ) {
84101
cfile += "index.html";
85102
}
86103
mem_map mf;
87104
mf.set_file( cfile );
88-
http_response msg;
89105
if ( mf.init() ) {
90106
msg.init( "200", "OK" );
91107
msg.add_hdr( "Content-Type", get_content_type( cfile ) );

0 commit comments

Comments
 (0)