h2o / h2o

H2O - the optimized HTTP/1, HTTP/2, HTTP/3 server
https://h2o.examp1e.net
MIT License
10.86k stars 840 forks source link

Basic Auth handler keeps asking for password on my web app #3417

Open ap-viavi opened 6 days ago

ap-viavi commented 6 days ago

I am trying the Basic Authentication mruby handler and it kinda works, however it asks for authentication 3 times.

What finally renders it unusable is silently failing Javascript fetch commands with {"message":"invalid username or password"} without even asking for more authentication.

This happens with a pure HTML5 web app accessed from Chrome.

Is there a way to persist authentication state for a connection, without having to change the Web app code (too much)?

ap-viavi commented 6 days ago

I found a workaround by applying the authentication handler only to /index.html or any other essential file in your website.

utrenkner commented 6 days ago

I have used that handler for years without any problems. Maybe post your config, so that we can have a look at it?

ap-viavi commented 6 days ago

Here is my config. It runs inside a Ubuntu 24 based container with a popular Python REST framework serving the main app, then Grafana and InfluxDB on other ports.

hosts:
    paths:
      # Basic Authentication
      /:
        mruby.handler: |
          require "htpasswd.rb"
          Htpasswd.new("etc/.htpasswd", "Demo server")
        proxy.reverse.url: http://127.0.0.1:8000/
      /grafana:
        proxy.reverse.url: http://127.0.0.1:3000/
      /influx:
        proxy.reverse.url: http://127.0.0.1:8086/

access-log: /dev/null
error-log: /dev/stderr
crash-handler: /bin/cat
header.unset: X-Frame-Options

proxy.timeout.io: 60000  # Some requests take long
proxy.preserve-host: ON
proxy.emit-x-forwarded-headers: ON # Report client address to inner services
proxy.emit-via-header: OFF

http2-casper: OFF
http2-idle-timeout: 99
http2-reprioritize-blocking-assets: OFF
http2-max-concurrent-requests-per-connection: 250
http2-graceful-shutdown-timeout: 0

listen:
  port: 80
ap-viavi commented 6 days ago

The app is pretty complex with a lot of JS calls to different paths under "/"

ap-viavi commented 4 days ago

Also there is an