Repository navigation
Store condition values as typed; remove the unused geolocation license key (#60, #54) - #61
Merged
Merged
Conversation
The rule screen read every setting through sanitize_textarea_field(), which turns < into < (or strips it) and deletes %xx sequences. Conditions and referenced lists are now read as typed, less control characters, and checked by the type's validator (UTF-8, at most 4096 characters, regex compilation). Rate-limit lines are verbatim. The Import, Rules and Advanced screens and the Test screen read their documents and request fields the same way. Input values are printed with every ampersand encoded, so a value containing an entity posts back unchanged.
Nothing read it: the plugin only compiles a local-database reader. The field, its default, validation and secret path are gone. Schema 13 deletes every stored key from geolocation and ASN rules, writing the settings only when one was removed. An imported document that still carries the key is imported without it, with a note in the preview and in WP-CLI's import output.
sean-e-dietrich
marked this pull request as ready for review
October 1, 2026 00:16
This was referenced Oct 1, 2026
Merged
sean-e-dietrich
added a commit
that referenced
this pull request
Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two changes the maintainer decided on.
Fixes #60
Fixes #54
Summary
Condition values are stored as typed (#60)
Where it broke.
Screen::posted_array()passes every posted setting throughsanitize_deep(), which callssanitize_textarea_field(). That function turns<into<(or strips it along with whatever follows) and deletes every%xxsequence. #59 worked around it only for fields markedverbatim. So condition values on every condition rule type, every field of a referenced list, and rate-limit lines were still rewritten on each save. The same sanitiser sat in front of the pasted document on the Import and Rules screens and the Advanced YAML box.What changed.
Rule_Edit_Screen::with_typed_conditions()re-reads theconditionsandsourcessubtrees from$_POST. It applieswp_unslash()andScreen::typed()(removes C0 control characters and DEL, keeps tabs, keeps line breaks only in a list's multi-lineadvancedblock). Keys still go throughsanitize_key(). Rate-limitpathsis nowverbatim, and verbatim fields go throughtyped()as well.Condition_Rule_Type_Base::validate_settings()makes the decisions, for every writer (screen, import, WP-CLI): it drops control characters, refuses invalid UTF-8 and values over 4,096 characters, and still checks the operator, the variable and that a regex compiles.posted_typed_textarea(). The Test screen reads path, user agent, headers and body withposted_typed()/posted_typed_textarea(), so it tests the request that was typed.Screen::text()insidewp_kses(). Textareas useesc_textarea(). Selects, the rule-list summary, notices, the import preview and the Test screen's result useesc_html()/esc_attr(). Every one of these paths escapes. One round-trip bug turned up along the way:esc_attr()does not double-encode, so a stored value of<xwas rendered asvalue="<x", the browser read it as<x, and the next save changed it.text()and the option values inselect()now usehtmlspecialchars(..., double_encode: true).The geolocation license key is removed (#54)
reader.license_keysecret path on both types. Its removal fromreader_help()also takes away the secret-field handling, which was generic.license_keystays in the generic Advanced YAML credential-name list and in the compiled-file key list.Upgraderroutine 13) removeslicense_keyfrom the reader of every stored geolocation and ASN rule. It writes the settings only if it removed something, so it is idempotent. Referenced lists never held the key, so they need no migration.settings_droppedsummary key) andwp basic-firewall importname each rule the key was dropped from. The import does not fail.Testing
New
tests/integration/ConditionValueRoundTripTest.php:<script>…,>,%2e%2e/,%3Cscript,&,<…>, quotes, backslashes, unicode, tab, and a regex(<|%3c)script\s*>. This runs for URL (header and query), user agent, geolocation, ASN and edge signal.<script.<>&", advancedwhere) and a percent-encoded rate-limit pattern come back unchanged.Request_Tester: a savedheader.x-probe contains %3CscriptblocksX-Probe: q=%3Cscript%3Eand letsX-Probe: a script tagthrough. Through the sanitiser the rule becamecontains script, which matches both. The regex matches both<script>and%3cscript. A header is used because 2.35 normalises unreserved percent-encodings inpath(%2eis.before a condition sees it) and Symfony decodesquery.*values.mainand pass here.UpgradeRoutinesTest::test_the_license_key_is_deleted_on_upgrade: keys are removed from geolocation and ASN rules, everything else is kept, and a second run writes nothing.GeoReaderSettingsTest: the field is not rendered, an import drops the key with a note (the key is never echoed), there is no note without a key, and the key is not a declared credential. Existing license-key tests were updated:RuleCredentialFieldsTestnow covers only the AbuseIPDB key.Local: unit (326),
composer analyse,composer lint, integration (639, 19 skipped, 2 pre-existing short-DB_PASSWORD warnings), e2e (13),tests/cli/commands.sh(36),build/check-versions.sh,build/build-zip.sh. The site'sbasic_firewall_settingsare byte-identical before and after. The schema version is now 13.CircleCI: green.
Was AI used in this pull request?