Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ add_executable(helloworld helloworld.cpp)
add_warnings_optimizations(helloworld)
target_link_libraries(helloworld PUBLIC Crow::Crow)

add_executable(helloworld_inject helloworld_inject.cpp)
add_warnings_optimizations(helloworld_inject)
target_link_libraries(helloworld_inject PUBLIC Crow::Crow)

# If compression is enabled, the example will be built
if("compression" IN_LIST CROW_FEATURES)
add_executable(example_compression example_compression.cpp)
Expand Down
16 changes: 0 additions & 16 deletions examples/helloworld_inject.cpp

This file was deleted.

32 changes: 32 additions & 0 deletions tests/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2806,3 +2806,35 @@ TEST_CASE("option_header_passed_in_full")
CHECK(res.find(ServerName) != std::string::npos);
app.stop();
}


TEST_CASE("inject_header_via_set_haeder")
{
crow::SimpleApp app;

CROW_ROUTE(app, "/")
([](const crow::request &req, crow::response &res) {
res.write("Hello, world!");
res.set_header("X-Custom", "safe\r\nInjected: yes");
res.add_header("X-Custom2", "safe\r\nInjected: yes");

res.end();
//return "Hello, world!";
});

app.validate();

auto _ = app.bindaddr(LOCALHOST_ADDRESS).port(45451).server_name("lol").run_async();
app.wait_for_server_start();

{
//
auto resp = HttpClient::request(LOCALHOST_ADDRESS, 45451,
"GET / HTTP/1.0\r\nHost: localhost\r\n\r\n");

CHECK(resp.find("\r\nInjected") == std::string::npos);
}

app.stop();
}

Loading