loco-rs / loco

🚂 🦀 The one-person framework for Rust for side-projects and startups
https://loco.rs
Apache License 2.0
3.91k stars 166 forks source link

`secure_headers` breaks `htmx` templates (in development) #745

Closed sectore closed 17 hours ago

sectore commented 5 days ago

Description

v0.8.0 introduced secure_headers middleware for setting secure headers by default (release notes).

It will break generated htmx templates in a way that its inline scripts can't be excecuted (htmx.defineExtension in this case). Same issue by referencing to static files, e.g. <script src="/static/example.js"></script>, which won't be executed.

BTW: A similar issue is mentioned by @martinjanda in issuecomment-2331363053

To Reproduce

docker run -d -p 5432:5432 \
  -e POSTGRES_USER=loco \
  -e POSTGRES_DB=loco_htmx_app_development \
  -e POSTGRES_PASSWORD="loco" \
  postgres:15.3-alpine
cargo loco generate scaffold movies name:string star:int active:bool --kind htmx
cargo loco start

error

Expected Behavior

Sending data as Content-Type: application/json.

expected

Possible fix

In config/development.yaml:


    secure_headers:
      preset: empty # instead of github
kaplanelad commented 3 days ago

Thanks for reporting this issue. fixed in https://github.com/loco-rs/loco/pull/737/commits/ef96e97ccc253626e00643ff8aae7f8ffc74e19f and release in the next Loco version