Release 0.2.7: patch rstr {N>100} bug, fixes cloudflare_origin_ca_key#15
Merged
Conversation
…_ca_key
rstr 3.2.x caps end_range at STAR_PLUS_LIMIT=100 unconditionally in
_handle_repeat. For fixed counts like {146} this pushes end below start
and randint raises. Monkeypatch Xeger._handle_repeat at module import so
the cap only applies when it leaves end>=start. Cloudflare-style rules
with {146} now generate 30/30 real matches.
kubernetes_secret_yaml still has low-diversity samples (rstr fills
(?s:.){0,100}? with control-char garbage); disclosed as known limitation.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Summary
Fixes the last of the 6
community.jsonrules the other team flagged:cloudflare_origin_ca_keynow generates 30/30 real matches instead of being skipped. Root cause was an rstr bug that misapplied an unbounded-quantifier cap to fixed-count{N}repetitions.Root cause
rstr 3.2.x's
Xeger._handle_repeat:Meant to bound unbounded
*/+quantifiers. But for a fixed{146}, sre_parse passesstart=146, end=146; rstr computesmin(146, 100) = 100and thenrandint(146, 100)raisesValueError: empty range. Real-world trigger: gitleaks rulecloudflare_origin_ca_keymatchesv1.0-<24 hex>-<146 hex>.Fix
Monkeypatch
rstr.xeger.Xeger._handle_repeatatcrossfire.generatorimport so the cap only applies when it still leavesend_range >= start_range. PreservesSTAR_PLUS_LIMITintent for unbounded quantifiers and wide variable ranges; fixed-count repetitions above the cap produce their exact count.Results on community.json (all 90 rules, 30 samples each)
ssh_private_keyprivate_key_peminst_tagatlassian_api_tokencloudflare_origin_ca_keykubernetes_secret_yamlKnown limitation (disclosed)
kubernetes_secret_yamlnow generates 30 samples, but the middle span generated by(?s:.){0,100}?is random control-character garbage identical across samples. Fixing needs either rule-aware sampling or a structured-input generator; out of scope here and acknowledged as nice-to-have by the other team.Test plan
pytest— 268 passed (adds 4 regression tests inTestRstrRepeatPatch)ruff check,ruff format --check,mypy --strict crossfire/cleancommunity.jsonnow produces samples for all 90 rules (was 89/90 on 0.2.6, 88/90 on 0.2.5)Breaking changes
None. The rstr monkeypatch affects only the
rstr.xeger.Xegerclass in this process after importingcrossfire.generator; callers that importcrossfire.generatorget the fix automatically. Patch stays until a fixed rstr release is out.Release note
After merge: tag
v0.2.7and push to trigger PyPI.