Skip to content

Fix %{HTTPS} / mod_rewrite compatibility for RPAFsethttps - #4

Merged
y-ken merged 1 commit into
masterfrom
fix/https-mod-rewrite-compat
Jun 12, 2026
Merged

Fix %{HTTPS} / mod_rewrite compatibility for RPAFsethttps#4
y-ken merged 1 commit into
masterfrom
fix/https-mod-rewrite-compat

Conversation

@y-ken

@y-ken y-ken commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Overview

Port the fix from gnif/mod_rpaf#6: mod_rewrite reads SSL state through the ssl_is_https optional function rather than the HTTPS environment variable, and it re-runs post_read_request, which dropped the HTTPS subprocess_env value on the second pass.

  • Store the HTTPS state in connection->notes ("rpaf_https") in addition to subprocess_env, and restore it early when the hook runs again so %{ENV:HTTPS} stays set across mod_rewrite's re-processing.
  • Register an ssl_is_https optional function (only when mod_ssl is not loaded) that reports the note, so RewriteCond %{HTTPS} works directly instead of requiring %{ENV:HTTPS}.
  • Unset the note in the request cleanup.

Japanese following English


概要

RPAFsethttps On で HTTPS を設定しても、mod_rewriteRewriteCond %{HTTPS} が常に off と判定される問題を修正します。gnif/mod_rpaf#6 で加えられた修正を取り込んだものです。

問題

mod_rewrite は SSL の状態を HTTPS 環境変数ではなく ssl_is_https というオプション関数で判定します。そのため:

  • %{ENV:HTTPS} は mod_rpaf が設定した値で正しく動く
  • しかし %{HTTPS} を直接使うと常に off を返す

加えて mod_rewritepost_read_request を再実行するため、2 回目の呼び出しで subprocess_envHTTPS 値が失われていました。

修正内容

  • HTTPS の状態を subprocess_env に加えて connection->notesrpaf_https)にも保存し、フックが再実行された際に早期復元することで、mod_rewrite の再処理をまたいでも %{ENV:HTTPS} が維持されるようにした
  • mod_ssl が未ロードの場合のみ ssl_is_https オプション関数を登録し、RewriteCond %{HTTPS}%{ENV:HTTPS} を使わずに直接動くようにした
  • リクエストのクリーンアップ時に rpaf_https ノートを削除

テスト

CentOS 6 / Apache 2.2 のコンテナ上で、本修正込みのコードが正常にビルドされ、CI の機能テスト(#2 を再現: 許可IP→200 / 非許可IP→403)が通ることをローカルで確認済みです。

🤖 Generated with Claude Code

Port the fix from gnif/mod_rpaf#6: mod_rewrite reads SSL state through the
ssl_is_https optional function rather than the HTTPS environment variable,
and it re-runs post_read_request, which dropped the HTTPS subprocess_env
value on the second pass.

  * Store the HTTPS state in connection->notes ("rpaf_https") in addition to
    subprocess_env, and restore it early when the hook runs again so
    %{ENV:HTTPS} stays set across mod_rewrite's re-processing.
  * Register an ssl_is_https optional function (only when mod_ssl is not
    loaded) that reports the note, so RewriteCond %{HTTPS} works directly
    instead of requiring %{ENV:HTTPS}.
  * Unset the note in the request cleanup.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@y-ken
y-ken merged commit 1102c66 into master Jun 12, 2026
1 check passed
@y-ken
y-ken deleted the fix/https-mod-rewrite-compat branch June 12, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant