Skip to content

Add nonce-reuse protection and test vectors to internal/cryptox/aesgcm.goΒ #170

Description

@Jagadeeshftw

πŸ“Œ Description

internal/cryptox/aesgcm.go (83 lines) implements AES-GCM encryption presumably used for encrypting sensitive stored fields (e.g. tokens). AES-GCM security depends entirely on never reusing a nonce with the same key β€” there's currently no test asserting nonces are generated with sufficient randomness/uniqueness, and no known-answer test vectors.

🧩 Requirements and context

  • Add a test asserting nonces are generated via a CSPRNG and are unique across many encryptions (statistical uniqueness check, not full formal proof).
  • Add known-answer test vectors (encrypt/decrypt roundtrip with a fixed key/nonce/plaintext) to catch any accidental algorithm change.
  • Add a doc comment on the encrypt function stating the nonce-reuse hazard explicitly.

Non-functional requirements

  • Must be secure, tested, and documented.
  • Should be efficient and easy to review.

πŸ› οΈ Suggested execution

1. Fork the repo and create a branch

git checkout -b test/aesgcm-nonce-reuse-protection

2. Implement changes

  • Modify: create/extend internal/cryptox/aesgcm_test.go with KAT vectors and a nonce-uniqueness test.
  • Modify: internal/cryptox/aesgcm.go β€” add the doc comment; fix only if a real reuse risk is found (e.g. a counter that can wrap).

3. Test and commit

  • Run tests:
go test ./internal/cryptox/... -v
  • Cover edge cases: ciphertext tampering is rejected, wrong key on decrypt fails cleanly, empty plaintext roundtrips correctly.
  • Include test output and details in the PR description.

Example commit message

test: add nonce-uniqueness checks and KAT vectors for AES-GCM helper

βœ… Acceptance criteria

  • Nonce generation source is confirmed cryptographically random.
  • KAT vectors pass and are committed to guard against future algorithm drift.
  • Tampered ciphertext is rejected (auth tag check works).

πŸ”’ Security notes

This is the encryption primitive likely protecting stored OAuth/GitHub tokens (internal/github/token_store.go). A nonce-reuse bug would be a full confidentiality break for whatever it encrypts β€” treat any finding here as high severity.

πŸ“‹ Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issuebackendBackend / API worksecuritySecurity hardening / audittestingTests and coverage

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions