Skip to content

fix(bootstrap): Handle malformed BOOTSTRAP values#927

Open
direkkakkar319-ops wants to merge 2 commits into
repository-service-tuf:mainfrom
direkkakkar319-ops:functionNone-DirekKakkar
Open

fix(bootstrap): Handle malformed BOOTSTRAP values#927
direkkakkar319-ops wants to merge 2 commits into
repository-service-tuf:mainfrom
direkkakkar319-ops:functionNone-DirekKakkar

Conversation

@direkkakkar319-ops

@direkkakkar319-ops direkkakkar319-ops commented Apr 9, 2026

Copy link
Copy Markdown

Description

Fixes a bootstrap edge case where unexpected Redis BOOTSTRAP string formats could cause bootstrap_state() to return None and crash callers with AttributeError.

if len(bootstrap.split("-")) == 1:
    ...  return bootstrap_state
elif len(bootstrap.split("-")) == 2:
    ...  return bootstrap_state
# ← falls off the end, returns None

Addeed a fallback else branch that returns a safe default and logs a warning

else:
    logging.warning(f"Unexpected bootstrap value format: {bootstrap!r}")
    return BootstrapState(bootstrap=False, state="unknown", task_id=None)

Also adds a unit test covering a malformed 3-segment bootstrap value.

tests cases pass
Screenshot 2026-04-10 000756

linting passes
Screenshot 2026-04-10 000709

impact

A corrupted or unexpected Redis value brings down the API entirely — a silent DoS on the bootstrap machinery. All endpoints that call bootstrap_state() are affected.

testing

test ran fro confirming the fix

$env:RSTUF_BOOTSTRAP_NODE='true'; $env:RSTUF_BROKER_SERVER='fakeserver'; $env:RSTUF_REDIS_SERVER='redis://fakeredis'; .\.venv\Scripts\python -m pytest -q tests/unit/tuf_repository_service_api/test__init__.py -k unexpected_format

output

.                                                                        [100%]
============================== warnings summary ===============================
.venv\Lib\site-packages\_pytest\cacheprovider.py:475
  F:\repository-service-tuf-api\.venv\Lib\site-packages\_pytest\cacheprovider.py:475: PytestCacheWarning: could not create cache path F:\repository-service-tuf-api\.pytest_cache\v\cache\nodeids: [WinError 183] Cannot create a file when that file already exists: 'F:\\repository-service-tuf-api\\.pytest_cache\\v\\cache'
    config.cache.set("cache/nodeids", sorted(self.cached_nodeids))

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
1 passed, 6 deselected, 1 warning in 0.25s

Types of changes

  • Bug fix
  • New feature
  • Breaking change

Additional requirements

  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

Use of AI

  • AI was used to generate or assist with generating this PR.

Code of Conduct

  • I agree to follow this project's Code of Conduct

…ression test`

Signed-off-by: Direk Kakkar <millioniar1717@gmail.com>
@direkkakkar319-ops direkkakkar319-ops marked this pull request as ready for review April 9, 2026 18:58
@direkkakkar319-ops

Copy link
Copy Markdown
Author

Hi, @kairoaraujo thius PR addeds a defensive fallback in bootstrap_state() for malformed BOOTSTRAP values (returns safe unknown state + warning) and covered it with a regression test for a 3-segment input.

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