Skip to content

Commit 10c0cb5

Browse files
feat: better helmet implementation of hsts.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
1 parent 8e0e20b commit 10c0cb5

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

include/boost/http_proto/server/helmet.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ enum class cross_domain_policy_type
207207
/** Groups the hsts constants here. */
208208
namespace hsts {
209209
inline static constexpr bool preload = true;
210+
inline static constexpr bool no_preload = false;
211+
inline static constexpr bool no_subdomains = false;
210212
inline static constexpr bool include_subdomains = true;
211213
inline static constexpr size_t default_age = 31536000;
212214
}
@@ -329,7 +331,15 @@ option_pair x_content_type_options();
329331

330332
option_pair content_security_policy(const helmet::csp_policy& sp);
331333

332-
option_pair strict_transport_security(const std::size_t age, const bool include_domains = true, const bool preload = false);
334+
/** Return HSTS configuration for the host.
335+
@param include_subdomains either include_domains or no_subdomains
336+
@param preload either preload or no_preload
337+
@note use the hsts namespace to set those function values.
338+
@return the option_pair to pass to the helmet.
339+
*/
340+
option_pair strict_transport_security(std::size_t age,
341+
bool include_subdomains = hsts::include_subdomains,
342+
bool preload = hsts::no_preload);
333343

334344
option_pair cross_origin_opener_policy(const coop_policy_type& policy = coop_policy_type::same_origin);
335345

src/server/helmet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ option_pair cross_origin_embedder_policy(const coep_policy_type& policy)
373373
return {"Cross-Origin-Embedder-Policy", {value}};
374374
}
375375

376-
option_pair strict_transport_security(const std::size_t age, const bool include_domains, const bool preload)
376+
option_pair strict_transport_security(std::size_t age, bool include_domains, bool preload)
377377
{
378378
std::string value = "max-age=" + std::to_string(age);
379379

test/unit/server/helmet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ struct helmet_test
252252
helmet_options opt;
253253
helmet::csp_policy csp;
254254

255-
csp.append("default-src", csp_type::self);
256-
csp.append("script-src", csp_type::self);
257-
csp.append("style-src", csp_type::self);
255+
csp.allow("default-src", csp_type::self)
256+
.allow("script-src", csp_type::self)
257+
.allow("style-src", csp_type::self);
258258

259259
opt.set(content_security_policy(csp));
260260

0 commit comments

Comments
 (0)