Skip to content

Add scan check upon download#762

Open
Schmarvinius wants to merge 3 commits intomainfrom
feature/454-malware-scan-on-download
Open

Add scan check upon download#762
Schmarvinius wants to merge 3 commits intomainfrom
feature/454-malware-scan-on-download

Conversation

@Schmarvinius
Copy link
Collaborator

@Schmarvinius Schmarvinius commented Mar 22, 2026

Add Rescan-on-Download Check for Attachments

New Feature

✨ Implements a rescan-on-download mechanism for attachments. When a user attempts to download an attachment that was last scanned more than 3 days ago (as recommended by the SAP Malware Scanning Service FAQ), the handler automatically transitions the attachment status to SCANNING, triggers an asynchronous malware rescan, and rejects the current download. The client must retry after the rescan completes.

Previously, only attachments with UNSCANNED, SCANNING, or null status were blocked/rescanned. Now, even CLEAN attachments are rescanned if their scan timestamp is stale or missing.

Changes

  • Registration.java: Passes the PersistenceService to the ReadAttachmentsHandler constructor.

  • ReadAttachmentsHandler.java:

    • Added PersistenceService as a constructor dependency.
    • Introduced RESCAN_THRESHOLD constant (3 days) to define the staleness window.
    • Refactored status check into needsScan(status, scannedAt) and isScanStale(scannedAt) helper methods.
    • Added transitionToScanning(entity, attachment) method that updates the attachment status to SCANNING in the persistence layer before triggering the async scan.
    • Updated Javadoc to describe the new rescan-on-download behavior.
  • BeforeReadItemsModifier.java: Extended the CQN modifier to also include the scannedAt field in select items, ensuring the timestamp is available during the read event for staleness checks. Updated log messages and Javadoc accordingly.

  • ReadAttachmentsHandlerTest.java: Added new test cases covering:

    • Stale clean attachment triggers rescan and status transition.
    • Clean attachment with null scannedAt triggers rescan.
    • Fresh clean attachment (within threshold) does not trigger rescan.
    • Clean attachment scanned exactly at threshold boundary.
    • PersistenceService is not called for UNSCANNED attachments.
  • BeforeReadItemsModifierTest.java: Added test helpers and assertions to verify that scannedAt is included in select items for both expand and direct select scenarios.

  • 🔄 Regenerate and Update Summary

📬 Subscribe to the Hyperspace PR Bot DL to get the latest announcements and pilot features!

PR Bot Information

Version: 1.19.1 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • LLM: anthropic--claude-4.6-sonnet
  • Summary Prompt: Default Prompt
  • Event Trigger: pull_request.opened
  • Correlation ID: c303a440-25ff-11f1-8efb-8ca01d295655
  • Output Template: Default Template

Copy link
Contributor

@hyperspace-insights hyperspace-insights bot left a comment

Choose a reason for hiding this comment

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

The PR introduces a useful rescan-on-download feature but has several correctness issues: the DB update predicate uses contentId instead of the row's primary key (risking unintended multi-row updates), the staleness boundary condition is ambiguous due to strict isAfter semantics, and the "exactly at threshold" test actually tests a 2-day-old scan rather than the real 3-day boundary—meaning the true edge case goes untested. Please address these before merging.

PR Bot Information

Version: 1.19.1 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • Event Trigger: pull_request.opened
  • LLM: anthropic--claude-4.6-sonnet
  • Correlation ID: c303a440-25ff-11f1-8efb-8ca01d295655

Add scannedAt to AttachmentModificationResult so that when
an attachment service handler (e.g. TestPluginAttachmentsServiceHandler)
sets both status=CLEAN and scannedAt on create, the timestamp is
persisted to the DB via CreateAttachmentEvent. Without this, scannedAt
remained null for CLEAN attachments, causing the rescan-on-download
logic to incorrectly treat them as stale.
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.

1 participant