Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#7875] Fix attachment processing #7932

Merged
merged 6 commits into from
Oct 3, 2023
Merged

Commits on Oct 2, 2023

  1. Update attachment masking before action callbacks

    We're going to make a change which might mean attachments might be
    rebuilt within the `FoiAttachmentMaskJob` this means the signed global
    ID might not return the attachment in this controller. This change
    ensures their is a referer parameter and if the attachment can't be
    loaded then we redirect back to the referer.
    
    Note, we don't need to worry about people modifying the referer to get
    users redirected to a third party domain as this is protected against by
    Rails.
    gbp committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    af8509e View commit details
    Browse the repository at this point in the history
  2. Remove attachment prominence check

    This check isn't doing anything. It was meant to protect when parsing
    incoming messages to stop hidden attachments from being made public
    again.
    
    We don't actually yet have this parsing in place instead we've focused
    on finding the original attachment [1].
    
    For the remainder of cases we will need to parse the raw email again but
    we have added separate check [2] so this one here is redundant.
    
    [1] #7875
    [2] #7920
    gbp committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    5839ac1 View commit details
    Browse the repository at this point in the history
  3. Update FoiAttachmentMaskJob

    Catch and rescue from `MissingAttachment` exceptions. Re-parse the
    incoming message to rebuild the attachments instead.
    
    Fixes: #7875
    gbp committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    5d5f262 View commit details
    Browse the repository at this point in the history
  4. Update FoiAttachment#body

    When attachment is unmasked we attempt to run the mask job inline. This
    commit makes a couple of changes.
    
    1. It unlocks the job so we can run it, so we don't have to worry about
       if the job doesn't run
    2. Now the mask job can call `IncomingMessage#parse_raw_email!(true)` we
       need to handle to case where the attachment disappears after being
       rebuilt. This results in a `ActiveRecord::RecordNotFound` when
       reloading the instance.
    3. Add RebuiltAttachment exception which we can then catch and rescue
       later. See the next commit.
    gbp committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    f3a035e View commit details
    Browse the repository at this point in the history
  5. Add method to catch RebuiltAttachment exceptions

    When calling `FoiAttachment#body` this can now raise an exception due to
    the current attachment instance getting replaced and no longer existing
    in the database.
    
    We can catch and rescue from this by reloading the new attachment and
    calling the same code again.
    
    This is what `FoiAttachment.protect_against_rebuilt_attachments` does
    and should prevent exceptions when viewing requests which haven't be
    masked and cached yet. These will normally be very old attachments as
    this also need the `hexdigest` to be mismatched.
    gbp committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    b3b9b48 View commit details
    Browse the repository at this point in the history
  6. Improve exception message

    Exception notifications don't include the name of the exception so
    improve the message to make it clearer what the issue is.
    gbp committed Oct 2, 2023
    Configuration menu
    Copy the full SHA
    625c685 View commit details
    Browse the repository at this point in the history