Skip to content

chore(tests): add security tests#174

Merged
kessplas merged 20 commits into
stagingfrom
kessplas/security-tests
Apr 27, 2026
Merged

chore(tests): add security tests#174
kessplas merged 20 commits into
stagingfrom
kessplas/security-tests

Conversation

@kessplas

@kessplas kessplas commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Issue #, if available: #167

Description of changes:

  • Harden decryption against metadata tampering from pentest findings:
    • Reject unknown V3 wrapping algorithms in _decrypt_v3 to prevent downgrade from kms+context to kms.
    • Detect instruction file format confusion where injected V2 keys bypass V3 key-commitment verification.
    • Normalize CBC decryption errors to a fixed message to prevent padding oracle information leakage.
  • Added 11 Python integration tests covering wrapping algorithm downgrade, encryption context bypass, CBC error indistinguishability, and instruction file format confusion.
  • Added cross-language TestServer tests for V3 (all languages must reject) and V2 (Go/C++ reject, others known limitation) downgrade scenarios.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@kessplas kessplas changed the base branch from main to staging April 8, 2026 18:21
@kessplas kessplas changed the title Kessplas/security tests chore(tests): add security tests Apr 17, 2026
@kessplas kessplas marked this pull request as ready for review April 18, 2026 00:26
Comment on lines +92 to +95
# 3. Decryption with mismatched context MUST fail
with pytest.raises((S3EncryptionClientError, Exception)):
s3ec.get_object(Bucket=bucket, Key=key, EncryptionContext={"project": "beta"})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: This check for beta is for the test below, not this test. This test should reject the message outright, without fudging the EC, at least according to the docstrings.

This assert should be on decrypting with legacy disabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm partial to having both tests, I'll add another that tests that scenario.

Comment thread test/integration/test_i_security.py Outdated
"""Tampering x-amz-wrap-alg from 'kms+context' to 'kms' with wrong context.

The KmsV1 wrapping algorithm does not support encryption context.
The client MUST reject when a caller provides encryption context

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
The client MUST reject when a caller provides encryption context
The client MUST reject when a caller provides mismatched encryption context

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done, I also added a test for when the EC matches, since that MUST fail as well.

Comment thread test/integration/test_i_security.py Outdated
Comment on lines +358 to +359
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives.padding import PKCS7

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Move these imports to at least the class level, if not the module level.

Comment thread test/integration/test_i_security.py Outdated
not called in any production code path.
"""

def test_v2_keys_in_instruction_file_cause_format_confusion(self):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: this test appears to assert that there is an vulnerability, as compared to asserting that the vulnerability is mitigated. I am not sure we should be testing that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The vulnerability is mitigated, the comment is wrong. I'll fix it.

@kessplas kessplas merged commit 7ca15e8 into staging Apr 27, 2026
11 of 12 checks passed
@kessplas kessplas deleted the kessplas/security-tests branch April 27, 2026 20:25
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