Skip to content

Commit af98dfa

Browse files
committed
add testcase for injected header, removed executable sample
1 parent f550439 commit af98dfa

3 files changed

Lines changed: 32 additions & 20 deletions

File tree

examples/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ add_executable(helloworld helloworld.cpp)
77
add_warnings_optimizations(helloworld)
88
target_link_libraries(helloworld PUBLIC Crow::Crow)
99

10-
add_executable(helloworld_inject helloworld_inject.cpp)
11-
add_warnings_optimizations(helloworld_inject)
12-
target_link_libraries(helloworld_inject PUBLIC Crow::Crow)
13-
1410
# If compression is enabled, the example will be built
1511
if("compression" IN_LIST CROW_FEATURES)
1612
add_executable(example_compression example_compression.cpp)

examples/helloworld_inject.cpp

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/unittest.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,3 +2796,35 @@ TEST_CASE("option_header_passed_in_full")
27962796
CHECK(res.find(ServerName) != std::string::npos);
27972797
app.stop();
27982798
}
2799+
2800+
2801+
TEST_CASE("inject_header_via_set_haeder")
2802+
{
2803+
crow::SimpleApp app;
2804+
2805+
CROW_ROUTE(app, "/")
2806+
([](const crow::request &req, crow::response &res) {
2807+
res.write("Hello, world!");
2808+
res.set_header("X-Custom", "safe\r\nInjected: yes");
2809+
res.add_header("X-Custom2", "safe\r\nInjected: yes");
2810+
2811+
res.end();
2812+
//return "Hello, world!";
2813+
});
2814+
2815+
app.validate();
2816+
2817+
auto _ = app.bindaddr(LOCALHOST_ADDRESS).port(45451).server_name("lol").run_async();
2818+
app.wait_for_server_start();
2819+
2820+
{
2821+
//
2822+
auto resp = HttpClient::request(LOCALHOST_ADDRESS, 45451,
2823+
"GET / HTTP/1.0\r\nHost: localhost\r\n\r\n");
2824+
2825+
CHECK(resp.find("\r\nInjected") == std::string::npos);
2826+
}
2827+
2828+
app.stop();
2829+
}
2830+

0 commit comments

Comments
 (0)