Skip to content

Harden Textract Civil ID expiry extraction - #93

Open
willjy1 wants to merge 1 commit into
BAWES-Universe:masterfrom
willjy1:codex/harden-textract-civil-id-extractor
Open

Harden Textract Civil ID expiry extraction#93
willjy1 wants to merge 1 commit into
BAWES-Universe:masterfrom
willjy1:codex/harden-textract-civil-id-extractor

Conversation

@willjy1

@willjy1 willjy1 commented May 16, 2026

Copy link
Copy Markdown
Contributor

Related to #55

/claim #55

Scope

This is a narrow, non-overlapping Textract Civil ID expiry extractor hardening slice. It does not touch the Civil ID upload/remove S3 flow, S3 credential env-var PRs, IAM/bucket policy work, CloudTrail helpers, Xero/OneSignal/SQS/MediaConvert/SES/service-token slices, live AWS access, candidate data, or real credential values.

Summary

  • Make IdExpiryDateExtractor fail closed when Textract credentials or the S3 document bucket/region are missing.
  • Restrict Textract document reads to Civil ID objects under the photos/ prefix before calling AWS.
  • Log AWS/provider failures by code/type and return sanitized errors instead of raw exception text.
  • Prevent the Civil ID validation cron from overwriting an existing expiry date with today's date when OCR returns an ID but no date match.
  • Add docs and a static regression guard for the Textract/Civil ID extractor contract.

Verification

py -3 tests\check-textract-civil-id-extractor.py
# Textract Civil ID extractor hardening check passed.

git diff --check

py -3 -m py_compile tests\check-textract-civil-id-extractor.py

php -l could not be run here because PHP is not installed in this environment. The PHP changes are limited to the existing Textract component and one cron guard, and the regression script checks the security-sensitive behavior directly.

Safety boundary

No AWS/IAM/S3 API calls, key rotation/deletion, bucket policy changes, candidate records, Civil ID images, private exports, or credential values were accessed or included.

Transparency: automation-assisted; I reviewed the diff and validation before submitting.

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@willjy1 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 30 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fa97a833-b231-44d7-9c8a-f176070bb7c5

📥 Commits

Reviewing files that changed from the base of the PR and between 7b023ff and 97577ac.

📒 Files selected for processing (4)
  • common/components/IdExpiryDateExtractor.php
  • console/controllers/CronController.php
  • docs/textract-civil-id-extractor.md
  • tests/check-textract-civil-id-extractor.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@BAWES BAWES 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.

Approved — Textract Civil ID expiry extractor hardening

Review: Solid refactoring. All checks green.

  • Makes region and bucket configurable (previously hardwired to Yii::$app->resourceManager)
  • Adds lazy configuration with graceful degradation (stores configurationError, warns instead of crashing)
  • Adds path traversal protection via isSafeDocumentName() — rejects absolute paths, protocol wrappers, dot-dot, and requires photos/ prefix
  • Catches Throwable (not just AwsException) for broader resilience
  • Returns structured error responses instead of raw exception messages

This is defense-in-depth — prevents both credential leaks and path injection in document names.

GitGuardian ✅ | CodeRabbit ✅ (skipped)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants