Skip to content

Upd. Firewall. Improve fw check. - #763

Open
svedge wants to merge 4 commits into
devfrom
upd-fw-pass-from-my
Open

svedge wants to merge 4 commits into
devfrom
upd-fw-pass-from-my

Conversation

@svedge

@svedge svedge commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Replay protection is not atomic, and IPv6 normalization can reject valid tokens.

2 open issues
What changed in this PR

This PR adds a signed-token entry point for emergency firewall bypass, reusing the existing browser-secret mechanism and removing the legacy access-key bypass.

Changes:

  • Add JWT validation, replay tracking, and bypass activation.
  • Register authenticated and unauthenticated handlers and let bypass requests reach them.
  • Add tests for token validation, single-use behavior, and request recognition.
File Description
tests/​lib/​CleantalkSP/​SpbctWP/​Firewall/​FirewallBypassJwtTest.php Tests JWT bypass activation and rejection cases.
security-malware-firewall.php Registers the JWT bypass handlers.
lib/​CleantalkSP/​SpbctWP/​Firewall/​FirewallBypass.php Implements JWT validation and browser bypass issuance.
inc/​spbc-firewall.php Replaces legacy bypass checks with JWT request routing.

Review effort: Balanced

Comment thread lib/CleantalkSP/SpbctWP/Firewall/FirewallBypass.php Outdated
Comment thread lib/CleantalkSP/SpbctWP/Firewall/FirewallBypass.php Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Site isolation and valid-token handling have unresolved security and correctness issues.

1 open issue
2 previously missed issues

In code that hasn't changed since last review

Medium severity Verify renewed bypass cookies against the persisted secret

lib/​CleantalkSP/​SpbctWP/​Firewall/​FirewallBypass.php:311

When the browser already sends a bypass cookie, Cookie::getVariable() prefers the original filter_input(INPUT_COOKIE, ...) value over the new secret written to $_COOKIE. This check compares the old secret with the newly stored hash, so a valid renewal redirects home and skips activation auditing even though a new cookie was issued. Verify the persisted hash against $user_secret directly instead of rereading the incoming cookie.

Medium severity Preserve mapped IPv4 addresses during request-IP validation

lib/​CleantalkSP/​SpbctWP/​Firewall/​FirewallBypass.php:391

When REMOTE_ADDR is ::ffff:203.0.113.10, IP::get() removes the mapped prefix through the shared normalizeIPv6() helper, so this comparison rejects a valid token claiming either the plain or mapped IPv4 address. Preserve the mapped prefix through request-IP selection before canonicalizing it. Add a mapped-request/plain-token regression case; the existing test covers only the opposite direction.

2 resolved since last review

Review effort: Balanced

Comment thread lib/CleantalkSP/SpbctWP/Firewall/FirewallBypass.php Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Valid token redemptions can fail IP validation or incorrectly redirect home and omit the activation audit log.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Verify persisted bypass hash instead of stale incoming cookie

lib/​CleantalkSP/​SpbctWP/​Firewall/​FirewallBypass.php:311

When the request includes an old spbc_fw_bypass cookie, Cookie::getVariable() still reads that incoming value through filter_input() after setUserToken() updates $_COOKIE. A successful JWT redemption therefore redirects home and skips the activation audit log despite issuing a new bypass cookie. Verify the persisted hash against $user_secret directly instead of rereading the incoming cookie.

Medium severity Preserve IPv4-mapped addresses during request IP normalization

lib/​CleantalkSP/​SpbctWP/​Firewall/​FirewallBypass.php:390

For a request address of ::ffff:203.0.113.10, IP::get() calls the shared normalizeIPv6(), which removes the mapped-address marker and returns 0:0:0:0:0:0:cb00:710a. The new comparison therefore rejects valid tokens containing either 203.0.113.10 or ::ffff:203.0.113.10. Preserve the mapped address through IP detection before canonicalizing it, and add a regression case with a mapped request address, not just a mapped token.

1 resolved since last review

Review effort: Balanced

@svedge
svedge requested a review from Glomberg October 27, 2026 05:53
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.

2 participants