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

Use allow and block lists for uploading files and images #3556

Merged
merged 8 commits into from
Jan 14, 2025

Conversation

laevandus
Copy link
Contributor

@laevandus laevandus commented Jan 10, 2025

🔗 Issue Links

Resolves IOS-124

🎯 Goal

  • Use upload config for image and file uploads

📝 Summary

  • AttachmentQueueUploader consumes AppSettings and fails attachments based on the upload config
  • ComposerVC uses the allow list to set allowed UTI types to image and file pickers

🛠 Implementation

When we fetch AppSettings just after connecting the user, upload configs are also set to AttachmentQueueUploader. AttachmentQueueUploader then uses that information for failing uploads as soon as attachment upload start processing. The uploading state is set to failed.
In the ComposerVC we are creating pickers for selecting files and images. These pickers use UTI instead of mime types and file extension. Therefore, we need to convert upload configs to UTI types. The only time we restrict selecting files or images using the picker is when allowed lists are set.

🎨 Showcase

N/A

🧪 Manual Testing Notes

Note: block lists and allow lists work differently in pickers (technical reasons).

Upload configs are set using Stream Dashboard.

Upload configs are set using Stream Dashboard.

Case 1: Block list using path extensions

  1. Set upload config for image uploads to block path extensions .png (or more)
  2. Open a channel, use the image picker to select a blocked file
    Expected: user can pick the file, but upload fails immediately when sending the message

Repeat for file upload config with .pdf

Case 2: Block list using mime types

  1. Set upload config for image uploads to block path extensions image/png (or more)
  2. Open a channel, use the image picker to select a blocked file
    Expected: user can pick the file, but upload fails immediately when sending the message

Repeat for file upload config with application/pdf

Case 3: Allow list using path extensions

  1. Set file upload config for image uploads to allow only .png path extensions
  2. Open a channel, use the image picker to select allowed file
    Expected:
    ImagePicker: user can pick the file, but upload fails immediately when sending the message
    FilePicker: user can't pick the file

Repeat for file upload config with .pdf

Case 4: Allow list using mime types

  1. Set file upload config for image uploads to allow only image/png mime type
  2. Open a channel, use the image picker to select allowed file
    Expected:
    ImagePicker: user can pick the file, but upload fails immediately when sending the message
    FilePicker: user can't pick the file

Repeat for file upload config with application/pdf

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change should be manually QAed
  • Changelog is updated with client-facing changes
  • Changelog is updated with new localization keys
  • New code is covered by unit tests
  • Documentation has been updated in the docs-content repo

…hment uploader and in image and file pickers
@laevandus laevandus added 🌐 SDK: StreamChat (LLC) Tasks related to the StreamChat LLC SDK 🎨 SDK: StreamChatUI Tasks related to the StreamChatUI SDK ✅ Feature An issue or PR related to a feature labels Jan 10, 2025
@laevandus laevandus requested a review from a team as a code owner January 10, 2025 12:47
Comment on lines 408 to 418
let mediaTypes: [String] = {
let availableTypes = UIImagePickerController.availableMediaTypes(for: .savedPhotosAlbum) ?? ["public.image"]
let allowed = channelController?.client.appSettings?.imageUploadConfig.allowedUTITypes ?? []
return allowed.isEmpty ? availableTypes : allowed
}()
let picker = UIImagePickerController()
picker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .savedPhotosAlbum) ?? ["public.image"]
picker.mediaTypes = mediaTypes
picker.sourceType = .savedPhotosAlbum
picker.delegate = self
return picker
}()
Copy link
Contributor Author

@laevandus laevandus Jan 10, 2025

Choose a reason for hiding this comment

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

By default we get public.image and public.video from the availableMediaTypes. I researched it but I haven't found a way to convert these high level UTIs to their subtypes. If I could do that, I could:

  1. Get the list of all subtypes
  2. Filter all of the subtypes based on imageUploadConfig.blockedUTITypes and imageUploadConfig.allowedUTITypes

Currently I did not figure out how to handle the case where I would create imageUploadConfig with, let's say, blocked mime type of image/jpeg, and then assign UTI types to the picker which would exclude that mime type (aka public.jpeg in UTI terms).

So for now, I am only setting allow list to the picker. Which means that, I could still select a jpeg file and start the upload. Upload fails immediately because AttachmentQueueUploaded checks the block list. In this example, checking the image/jpeg mime type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I spent some more time and does not seem feasible. I'll keep it like that and if we end up finding a way, we can change it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am taking this out because it is a risky change. Did not realise this before. Picker will throw an exception if I would just do public.jpeg

@Stream-SDK-Bot
Copy link
Collaborator

SDK Size

title develop branch diff status
StreamChat 6.98 MB 7.0 MB +17 KB 🟢
StreamChatUI 4.77 MB 4.77 MB 0 KB 🟢

@Stream-SDK-Bot
Copy link
Collaborator

SDK Performance

target metric benchmark branch performance status
MessageList Hitches total duration 10 ms 3.34 ms 66.6% 🔼 🟢
Duration 2.6 s 2.54 s 2.31% 🔼 🟢
Hitch time ratio 4 ms per s 1.32 ms per s 67.0% 🔼 🟢
Frame rate 75 fps 78.42 fps 4.56% 🔼 🟢
Number of hitches 1 0.4 60.0% 🔼 🟢

Copy link
Member

@nuno-vieira nuno-vieira left a comment

Choose a reason for hiding this comment

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

LGTM! ✅

@laevandus laevandus changed the title [WIP] Use allow and block lists for uploading files and images Use allow and block lists for uploading files and images Jan 13, 2025
@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Jan 13, 2025

SDK Size

title develop branch diff status
StreamChat 6.98 MB 7.0 MB +18 KB 🟢
StreamChatUI 4.77 MB 4.77 MB 0 KB 🟢

@laevandus laevandus added the 🤞 Ready For QA A PR that is Ready for QA label Jan 13, 2025
CHANGELOG.md Outdated
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## StreamChat
### ✅ Added
- Use `AppSettings.fileUploadConfig` and `AppSettings.imageUploadConfig` for blocking attachment uploads [#3556](https://github.com/GetStream/stream-chat-swift/pull/3556/)
Copy link
Member

Choose a reason for hiding this comment

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

We also need to add an entry to StreamChatUI, maybe a # Changed section that we now change the media types based on these configs @laevandus WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, it should be mentioned. Thanks

@testableapple testableapple added 🟢 QAed A PR that was QAed and removed 🤞 Ready For QA A PR that is Ready for QA labels Jan 14, 2025
@laevandus laevandus enabled auto-merge (squash) January 14, 2025 11:34
@laevandus laevandus merged commit f3fccb0 into develop Jan 14, 2025
14 checks passed
@laevandus laevandus deleted the feature/app-settings-upload-configs branch January 14, 2025 12:23
@Stream-SDK-Bot Stream-SDK-Bot mentioned this pull request Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✅ Feature An issue or PR related to a feature 🟢 QAed A PR that was QAed 🌐 SDK: StreamChat (LLC) Tasks related to the StreamChat LLC SDK 🎨 SDK: StreamChatUI Tasks related to the StreamChatUI SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants