Skip to content

Commit

Permalink
Don't proxy media downloads when using tor
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jan 29, 2024
1 parent 687ecaf commit be16141
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions example-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ meta:
# Which service is this bridge for? Available options:
# * facebook - connect to FB Messenger via facebook.com
# * facebook-tor - connect to FB Messenger via facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd.onion
# (note: does not currently proxy media downloads)
# * messenger - connect to FB Messenger via messenger.com (can be used with the facebook side deactivated)
# * instagram - connect to Instagram DMs via instagram.com
#
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ func (br *MetaBridge) Init() {
msgconv.MediaReferer = "https://www.messenger.com/"
MessagixPlatform = types.Messenger
case config.ModeFacebookTor:
msgconv.MediaReferer = "https://www.facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd.onion/"
//msgconv.MediaReferer = "https://www.facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd.onion/"
// Media is currently not proxied for efficiency
// TODO make it configurable (requires passing the proxy to mediaHTTPClient)
msgconv.BypassOnionForMedia = true
msgconv.MediaReferer = "https://www.facebook.com/"
MessagixPlatform = types.FacebookTor
}
br.ProtocolName = "Facebook Messenger"
Expand Down
5 changes: 5 additions & 0 deletions msgconv/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net/http"
"net/url"
"path"
"strings"
"time"

"github.com/rs/zerolog"
Expand All @@ -43,8 +44,12 @@ var mediaHTTPClient = http.Client{
Timeout: 60 * time.Second,
}
var MediaReferer string
var BypassOnionForMedia bool

func DownloadMedia(ctx context.Context, url string) ([]byte, error) {
if BypassOnionForMedia {
url = strings.ReplaceAll(url, "facebookcooa4ldbat4g7iacswl3p2zrf5nuylvnhxn6kqolvojixwid.onion", "fbcdn.net")
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, fmt.Errorf("failed to prepare request: %w", err)
Expand Down

0 comments on commit be16141

Please sign in to comment.