BCH-1150: Validate evidence file type against evidence type on backend#408
Conversation
Reject screenshot evidence submissions where the file media type is not an image (png/jpg/jpeg/gif/webp). Adds screenshotAllowedMediaTypes and validates in validateEvidenceRequirements before checking required types. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR adds media-type validation for screenshot evidence submissions in workflow step transitions. An allowlist of image MIME types is defined, and the evidence validation logic is extended to reject screenshots with incompatible media types. Test coverage validates that screenshots accept only image types while document evidence accepts a broader set. ChangesScreenshot Evidence Media Type Validation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/workflow/step_transition_test.go`:
- Around line 304-309: The test loop in step_transition_test.go is missing the
"image/jpg" media type and thus is out of sync with the production allowlist
used in validateEvidenceRequirements; update the slice in the table-driven loop
that calls svc.validateEvidenceRequirements (which uses EvidenceSubmission) to
include "image/jpg" alongside "image/png", "image/jpeg", "image/gif", and
"image/webp" so the test covers all allowed image types.
In `@internal/workflow/step_transition.go`:
- Around line 304-306: The allowlist lookup for screenshot MIME types rejects
valid variants because evidence.MediaType is matched verbatim; normalize it
before checking by trimming whitespace, splitting off any parameters at the
first ';', and lowercasing the base type (e.g., use strings.TrimSpace,
strings.SplitN(media, ";", 2)[0], strings.ToLower). Replace the direct lookup of
evidence.MediaType against screenshotAllowedMediaTypes in the block that checks
evidence.EvidenceType == "screenshot" with the normalizedMedia value so
screenshotAllowedMediaTypes and the code that references evidence.MediaType use
the normalized base media type.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: aee22940-f085-429e-9b34-dec6dceffe38
📒 Files selected for processing (2)
internal/workflow/step_transition.gointernal/workflow/step_transition_test.go
… test coverage Add image/jpg to acceptance test loop to match the allowlist. Normalize media type (lowercase, strip parameters) before allowlist lookup so that values like Image/PNG or image/png; charset=binary are accepted. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Reject screenshot evidence submissions where the file media type is not an image (png/jpg/jpeg/gif/webp). Adds screenshotAllowedMediaTypes and validates in validateEvidenceRequirements before checking required types.
Summary by CodeRabbit
Bug Fixes
image/png; charset=binary); incompatible media types are rejected.Tests