Skip to content

fix: sign and verify on-disk pickle/FAISS caches with HMAC (APPENG-5695, APPENG-5696) - #321

Open
gnetanel wants to merge 5 commits into
RHEcosystemAppEng:mainfrom
gnetanel:APPENG-5695_and_APPENG-5696
Open

fix: sign and verify on-disk pickle/FAISS caches with HMAC (APPENG-5695, APPENG-5696)#321
gnetanel wants to merge 5 commits into
RHEcosystemAppEng:mainfrom
gnetanel:APPENG-5695_and_APPENG-5696

Conversation

@gnetanel

Copy link
Copy Markdown
Collaborator
  • Mitigate CWE-502 by HMAC-signing on-disk cache artifacts before any pickle deserialization.
  • APPENG-5695: Sign/verify document pickle caches and the runtime stdlib pickle cache (dump_pickle_signed / load_pickle_verified).
  • APPENG-5696: Sign/verify FAISS index artifacts (including index.pkl) on VDB write/load.
  • On integrity failure:
    • Document pickles / FAISS → discard or rebuild rather than loading untrusted pickle.
  • HMAC key is resolved from env / credential encryption secret / local key file — not stored alongside cache artifacts on the PVC.

@gnetanel
gnetanel requested a review from zvigrinberg July 30, 2026 12:00
@vbelouso

vbelouso commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@zvigrinberg zvigrinberg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi @gnetanel
Please see my comments.


def resolve_key_material() -> bytes:
"""Resolve HMAC key material from env, shared secret, or a local key file."""
for env_name in (CACHE_INTEGRITY_KEY_ENV, CREDENTIAL_ENCRYPTION_KEY_ENV):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@gnetanel If CACHE_INTEGRITY_KEY_ENV will be set in deployment and will used for the HMAC signing for creating pickle files , but in a restart it will be omitted, this will fall back to verify according to only CREDENTIAL_ENCRYPTION_KEY_ENV, which falsely will fail the verification before loading pickle files

Instead, go only for CREDENTIAL_ENCRYPTION_KEY_ENV, and omit the other one ( unless you want to add it to the deployment' secrets keys mounted into that env var)

Comment thread src/exploit_iq_commons/utils/cache_hmac_integrity.py Outdated
if value:
return value.encode("utf-8")

key_file = Path(os.environ.get(CACHE_INTEGRITY_KEY_FILE_ENV, str(_default_key_file())))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@gnetanel Don't fallback to default key file, it's security concern and error prone as well.
Instead, if env var is not populated ( you should decide if it's going to be CREDENTIAL_ENCRYPTION_KEY_ENV or CACHE_INTEGRITY_KEY_ENV) you should raise ValueError with an appropriate error message.

Comment thread src/exploit_iq_commons/utils/faiss_integrity.py Outdated
@gnetanel
gnetanel force-pushed the APPENG-5695_and_APPENG-5696 branch from e43539c to 5c2ffa5 Compare August 2, 2026 10:55
@gnetanel

gnetanel commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

/test vulnerability-analysis-on-pr

2 similar comments
@gnetanel

gnetanel commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

/test vulnerability-analysis-on-pr

@gnetanel

gnetanel commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

/test vulnerability-analysis-on-pr

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.

3 participants