Take Discord package permissions:
$ flatpak info --show-permissions com.discordapp.Discord
[Context]
shared=network;ipc;
sockets=x11;wayland;pulseaudio;
devices=all;
filesystems=xdg-download;xdg-pictures:ro;xdg-videos:ro;xdg-run/speech-dispatcher;
[Session Bus Policy]
org.kde.StatusNotifierWatcher=talk
com.canonical.AppMenu.Registrar=talk
org.freedesktop.ScreenSaver=talk
com.canonical.indicator.application=talk
com.canonical.Unity=talk
[System Bus Policy]
org.freedesktop.UPower=talk
[Environment]
XCURSOR_PATH=/run/host/user-share/icons:/run/host/share/icons
ELECTRON_TRASH=gio
Looking at the filesystems line, my understanding is this program is not able to access files in /tmp/ $HOME/ or / for that matter.
So the fact I can add file attachments in Discord from said paths must be due to xdg-portals.
How does flatpak ensure that the portals mechanism isn't abused by malicious programs?