Skip to content

Commit 79728c4

Browse files
committed
Merge branch 'master' into v1.3 to get sanitize header fix for new bugfix release
* master: (22 commits) fix#1165: sanitize header values to prevent injection and add helloworld_inject example (#1167) Handle headers for HTTPMethod::Options Fix build on OpenBSD (#1162) Enable compiler sanitizers for test builds (Fixes #1137) Enable compiler sanitizers for test builds (Fixes #1137) Enable compiler sanitizers for test builds (Fixes #1137) Feature#1129-CMake Error: ALIAS target "Boost::system" name collision when using vcpkg and FetchContent (#1133) Fix heap-buffer-overflow in query_string when parsing malformed '%'Fix heap-buffer-overflow in query_string for malformed '%' (#1134) Minor features to crow::json::wvalue (#1143) ... # Conflicts: # .github/workflows/build_and_test.yml
2 parents 737eac3 + 0e9aa2e commit 79728c4

18 files changed

Lines changed: 313 additions & 36 deletions

.github/workflows/build_and_test.yml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ jobs:
137137
shell: bash
138138

139139
- name: Save report
140-
uses: actions/upload-artifact@v6
140+
uses: actions/upload-artifact@v7
141141
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'gcc' && matrix.cxx_stdlib == 'libstdc++' && matrix.asio_type == 'boost' && !startsWith(github.ref, 'refs/heads/v')
142142
with:
143143
name: coveralls.json
@@ -159,7 +159,7 @@ jobs:
159159
shell: bash
160160

161161
- name: Upload Linux packages
162-
uses: actions/upload-artifact@v6
162+
uses: actions/upload-artifact@v7
163163
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'gcc' && matrix.cxx_stdlib == 'libstdc++' && matrix.asio_type == 'boost' && startsWith(github.ref, 'refs/heads/v')
164164
with:
165165
name: packages-linux
@@ -187,3 +187,36 @@ jobs:
187187
overwrite: true
188188
path: |
189189
${{github.workspace}}/build/Crow-*
190+
191+
sanitize:
192+
name: Sanitizer Tests (ASan + UBSan)
193+
runs-on: ubuntu-latest
194+
steps:
195+
- uses: actions/checkout@v6
196+
197+
- name: Install dependencies
198+
run: |
199+
sudo apt-get update
200+
sudo apt-get install -yq \
201+
libasio-dev \
202+
libssl-dev zlib1g-dev \
203+
cmake g++
204+
205+
- name: Configure with sanitizers
206+
run: |
207+
cmake --preset ci-sanitize \
208+
-DCROW_BUILD_TESTS=ON \
209+
-DCROW_ENABLE_SSL=ON \
210+
-DCROW_ENABLE_COMPRESSION=ON \
211+
-DCROW_ENABLE_SANITIZERS=ON
212+
213+
- name: Build
214+
run: cmake --build build/sanitize -j $(nproc)
215+
216+
- name: Test under sanitizers
217+
working-directory: ${{github.workspace}}/build/sanitize
218+
env:
219+
ASAN_OPTIONS: "strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1:detect_leaks=0"
220+
UBSAN_OPTIONS: "print_stacktrace=1"
221+
run: ctest --output-on-failure
222+

.github/workflows/cifuzz.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
fuzz-seconds: 800
2626
output-sarif: true
2727
- name: Upload Crash
28-
uses: actions/upload-artifact@v6
28+
uses: actions/upload-artifact@v7
2929
if: failure() && steps.build.outcome == 'success'
3030
with:
3131
name: artifacts

.github/workflows/submit_coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
if: github.event.workflow_run.conclusion == 'success'
1717
steps:
1818
- name: Download artifact
19-
uses: dawidd6/action-download-artifact@v14
19+
uses: dawidd6/action-download-artifact@v19
2020
with:
2121
workflow: ${{ github.event.workflow_run.workflow_id }}
2222
workflow_conclusion: success

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ find_package(Python3)
4747
option(CROW_BUILD_EXAMPLES "Build the examples in the project" ${CROW_IS_MAIN_PROJECT})
4848
option(CROW_BUILD_TESTS "Build the tests in the project" ${CROW_IS_MAIN_PROJECT})
4949
option(CROW_BUILD_FUZZER "Instrument and build Crow fuzzer" OFF)
50+
option(CROW_ENABLE_SANITIZERS "Enable sanitizers (ASan, UBSan) for test builds" OFF)
5051
option(CROW_AMALGAMATE "Combine all headers into one" OFF)
5152
option(CROW_INSTALL "Add install step for Crow" ON )
5253
option(CROW_USE_BOOST "Use Boost.Asio for Crow" OFF)
@@ -114,7 +115,9 @@ if(CROW_USE_BOOST)
114115
if(Boost_VERSION VERSION_LESS 1.89)
115116
find_package(Boost 1.64 COMPONENTS system REQUIRED)
116117
else()
117-
add_library(Boost::system ALIAS Boost::headers)
118+
if(NOT TARGET Boost::system)
119+
add_library(Boost::system ALIAS Boost::headers)
120+
endif()
118121
endif()
119122
target_link_libraries(Crow
120123
INTERFACE

CMakePresets.json

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"warnings": {
1313
"dev": true,
1414
"deprecated": true,
15-
"uninitialized": true,
15+
"uninitialized": false,
1616
"unusedCli": true,
1717
"systemVars": false
1818
},
@@ -81,7 +81,10 @@
8181
},
8282
{
8383
"name": "ci-linux",
84-
"inherits": ["flags-gcc-clang", "ci-std"],
84+
"inherits": [
85+
"flags-gcc-clang",
86+
"ci-std"
87+
],
8588
"generator": "Unix Makefiles",
8689
"hidden": true,
8790
"cacheVariables": {
@@ -90,13 +93,19 @@
9093
},
9194
{
9295
"name": "ci-darwin",
93-
"inherits": ["flags-appleclang", "ci-std"],
96+
"inherits": [
97+
"flags-appleclang",
98+
"ci-std"
99+
],
94100
"generator": "Xcode",
95101
"hidden": true
96102
},
97103
{
98104
"name": "ci-win64",
99-
"inherits": ["flags-msvc", "ci-std"],
105+
"inherits": [
106+
"flags-msvc",
107+
"ci-std"
108+
],
100109
"generator": "Visual Studio 17 2022",
101110
"architecture": "x64",
102111
"hidden": true
@@ -116,15 +125,21 @@
116125
},
117126
{
118127
"name": "ci-coverage",
119-
"inherits": ["coverage-linux", "dev-mode"],
128+
"inherits": [
129+
"coverage-linux",
130+
"dev-mode"
131+
],
120132
"cacheVariables": {
121133
"COVERAGE_HTML_COMMAND": ""
122134
}
123135
},
124136
{
125137
"name": "ci-sanitize",
126138
"binaryDir": "${sourceDir}/build/sanitize",
127-
"inherits": ["ci-linux", "dev-mode"],
139+
"inherits": [
140+
"ci-linux",
141+
"dev-mode"
142+
],
128143
"cacheVariables": {
129144
"CMAKE_BUILD_TYPE": "Sanitize",
130145
"CMAKE_CXX_FLAGS_SANITIZE": "-U_FORTIFY_SOURCE -O2 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fno-common"
@@ -145,15 +160,57 @@
145160
},
146161
{
147162
"name": "ci-macos",
148-
"inherits": ["ci-build", "ci-darwin", "dev-mode", "ci-multi-config"]
163+
"inherits": [
164+
"ci-build",
165+
"ci-darwin",
166+
"dev-mode",
167+
"ci-multi-config"
168+
]
149169
},
150170
{
151171
"name": "ci-ubuntu",
152-
"inherits": ["ci-build", "ci-linux", "clang-tidy", "cppcheck", "dev-mode"]
172+
"inherits": [
173+
"ci-build",
174+
"ci-linux",
175+
"clang-tidy",
176+
"cppcheck",
177+
"dev-mode"
178+
]
153179
},
154180
{
155181
"name": "ci-windows",
156-
"inherits": ["ci-build", "ci-win64", "dev-mode", "ci-multi-config"]
182+
"inherits": [
183+
"ci-build",
184+
"ci-win64",
185+
"dev-mode",
186+
"ci-multi-config"
187+
]
188+
}
189+
],
190+
"buildPresets": [
191+
{
192+
"name": "ci-sanitize",
193+
"configurePreset": "ci-sanitize",
194+
"configuration": "Sanitize",
195+
"jobs": 4
196+
}
197+
],
198+
"testPresets": [
199+
{
200+
"name": "ci-sanitize",
201+
"configurePreset": "ci-sanitize",
202+
"configuration": "Sanitize",
203+
"output": {
204+
"outputOnFailure": true
205+
},
206+
"execution": {
207+
"jobs": 4,
208+
"noTestsAction": "error"
209+
},
210+
"environment": {
211+
"ASAN_OPTIONS": "strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1:detect_leaks=0",
212+
"UBSAN_OPTIONS": "print_stacktrace=1"
213+
}
157214
}
158215
]
159-
}
216+
}

CMakeUserPresets.json

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,22 @@
99
{
1010
"name": "dev-common",
1111
"hidden": true,
12-
"inherits": ["dev-mode", "clang-tidy", "cppcheck"],
12+
"inherits": [
13+
"dev-mode",
14+
"clang-tidy",
15+
"cppcheck"
16+
],
1317
"cacheVariables": {
1418
"BUILD_MCSS_DOCS": "ON"
1519
}
1620
},
1721
{
1822
"name": "dev-linux",
1923
"binaryDir": "${sourceDir}/build/dev-linux",
20-
"inherits": ["dev-common", "ci-linux"],
24+
"inherits": [
25+
"dev-common",
26+
"ci-linux"
27+
],
2128
"cacheVariables": {
2229
"CMAKE_BUILD_TYPE": "Debug",
2330
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
@@ -26,12 +33,18 @@
2633
{
2734
"name": "dev-darwin",
2835
"binaryDir": "${sourceDir}/build/dev-darwin",
29-
"inherits": ["dev-common", "ci-darwin"]
36+
"inherits": [
37+
"dev-common",
38+
"ci-darwin"
39+
]
3040
},
3141
{
3242
"name": "dev-win64",
3343
"binaryDir": "${sourceDir}/build/dev-win64",
34-
"inherits": ["dev-common", "ci-win64"],
44+
"inherits": [
45+
"dev-common",
46+
"ci-win64"
47+
],
3548
"environment": {
3649
"UseMultiToolTask": "true",
3750
"EnforceProcessCountAcrossBuilds": "true"
@@ -45,7 +58,21 @@
4558
{
4659
"name": "dev-coverage",
4760
"binaryDir": "${sourceDir}/build/coverage",
48-
"inherits": ["dev-mode", "coverage-linux"]
61+
"inherits": [
62+
"dev-mode",
63+
"coverage-linux"
64+
]
65+
},
66+
{
67+
"name": "dev-sanitize",
68+
"binaryDir": "${sourceDir}/build/sanitize",
69+
"inherits": [
70+
"dev-mode",
71+
"ci-sanitize"
72+
],
73+
"cacheVariables": {
74+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
75+
}
4976
}
5077
],
5178
"buildPresets": [
@@ -54,6 +81,12 @@
5481
"configurePreset": "dev",
5582
"configuration": "Debug",
5683
"jobs": 10
84+
},
85+
{
86+
"name": "dev-sanitize",
87+
"configurePreset": "dev-sanitize",
88+
"configuration": "Sanitize",
89+
"jobs": 10
5790
}
5891
],
5992
"testPresets": [
@@ -68,6 +101,22 @@
68101
"jobs": 10,
69102
"noTestsAction": "error"
70103
}
104+
},
105+
{
106+
"name": "dev-sanitize",
107+
"configurePreset": "dev-sanitize",
108+
"configuration": "Sanitize",
109+
"output": {
110+
"outputOnFailure": true
111+
},
112+
"execution": {
113+
"jobs": 10,
114+
"noTestsAction": "error"
115+
},
116+
"environment": {
117+
"ASAN_OPTIONS": "strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1:detect_leaks=0",
118+
"UBSAN_OPTIONS": "print_stacktrace=1"
119+
}
71120
}
72121
]
73-
}
122+
}

cmake/compiler_options.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,24 @@ function(add_warnings_optimizations target_name)
4949
)
5050
endif()
5151
endfunction()
52+
53+
# Sanitizer flags for test builds (ASan + UBSan)
54+
function(add_sanitizer_flags target_name)
55+
if(CROW_ENABLE_SANITIZERS)
56+
if(MSVC)
57+
# MSVC supports /fsanitize=address but not UBSan
58+
target_compile_options(${target_name} PRIVATE /fsanitize=address)
59+
elseif(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
60+
target_compile_options(${target_name}
61+
PRIVATE
62+
-fsanitize=address,undefined
63+
-fno-omit-frame-pointer
64+
-fno-common
65+
)
66+
target_link_options(${target_name}
67+
PRIVATE
68+
-fsanitize=address,undefined
69+
)
70+
endif()
71+
endif()
72+
endfunction()

examples/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ 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+
1014
# If compression is enabled, the example will be built
1115
if("compression" IN_LIST CROW_FEATURES)
1216
add_executable(example_compression example_compression.cpp)

examples/helloworld_inject.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "crow.h"
2+
3+
int main()
4+
{
5+
crow::SimpleApp app;
6+
7+
CROW_ROUTE(app, "/")
8+
([](const crow::request &req, crow::response& res) {
9+
res.write("Hello, world!");
10+
res.set_header("X-Custom", "safe\r\nInjected: yes");
11+
res.end();
12+
//return "Hello, world!";
13+
});
14+
15+
app.port(18080).run();
16+
}

0 commit comments

Comments
 (0)