Opened 8 months ago

Closed 8 months ago

#6976 closed defect (invalid)

ffmpeg ignores user-agent http header

Reported by: Moipeg Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
How to reproduce: read http stream restricted by user agent

COMMAND:
% fmpeg -loglevel debug  -i http://cdnamd-hls-globecast.akamaized.net/live/ramdisk/radio_idaa_watanya/hls_snrt_radio/radio_idaa_watanya-video=100000-audio_AACL_qad_130400_110=130400.m3u8 -user_agent 'Safari' -user-agent 'Safari' -headers 'User-Agent: Safari' -vn -t 60 out.mp3

OUTPUT:
ffmpeg version N-89871-g388a0f7 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.5) 20160609
  configuration: --prefix=/home/aa --enable-avresample --enable-ffplay --enable-fontconfig --enable-frei0r --enable-gpl --enable-libass --enable-libcdio --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopencv --enable-libpulse --enable-librtmp --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-nonfree --enable-opengl --enable-static --enable-version3 --enable-libssh --enable-openssl --enable-opencl --enable-libfdk-aac --enable-libbs2b --enable-libcaca --enable-libfribidi --enable-libgme --enable-libmodplug --enable-libopenjpeg --enable-libopus --enable-libsoxr --enable-libwavpack --enable-libwebp --enable-libzmq --enable-libzvbi --enable-openal --enable-libx265
  libavutil      56.  7.100 / 56.  7.100
  libavcodec     58.  9.100 / 58.  9.100
  libavformat    58.  5.100 / 58.  5.100
  libavdevice    58.  0.101 / 58.  0.101
  libavfilter     7. 11.101 /  7. 11.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
Splitting the commandline.
Reading option '-i' ... matched as input url with argument 'http://cdnamd-hls-globecast.akamaized.net/live/ramdisk/radio_idaa_watanya/hls_snrt_radio/radio_idaa_watanya-video=100000-audio_AACL_qad_130400_110=130400.m3u8'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input url http://cdnamd-hls-globecast.akamaized.net/live/ramdisk/radio_idaa_watanya/hls_snrt_radio/radio_idaa_watanya-video=100000-audio_AACL_qad_130400_110=130400.m3u8.
Successfully parsed a group of options.
Opening an input file: http://cdnamd-hls-globecast.akamaized.net/live/ramdisk/radio_idaa_watanya/hls_snrt_radio/radio_idaa_watanya-video=100000-audio_AACL_qad_130400_110=130400.m3u8.
[NULL @ 0x3f82840] Opening 'http://cdnamd-hls-globecast.akamaized.net/live/ramdisk/radio_idaa_watanya/hls_snrt_radio/radio_idaa_watanya-video=100000-audio_AACL_qad_130400_110=130400.m3u8' for reading
[http @ 0x3f83280] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy'
[http @ 0x3f83280] request: GET /live/ramdisk/radio_idaa_watanya/hls_snrt_radio/radio_idaa_watanya-video=100000-audio_AACL_qad_130400_110=130400.m3u8 HTTP/1.1
User-Agent: Lavf/58.3.100
Accept: */*
Range: bytes=0-
Connection: close
Host: cdnamd-hls-globecast.akamaized.net
Icy-MetaData: 1


[http @ 0x3f83280] HTTP error 403 Forbidden
http://cdnamd-hls-globecast.akamaized.net/live/ramdisk/radio_idaa_watanya/hls_snrt_radio/radio_idaa_watanya-video=100000-audio_AACL_qad_130400_110=130400.m3u8: Server returned 403 Forbidden (access denied)




ffmpeg version N-89871-g388a0f7 
Built on 2018-01-22

As you can see, I used all the three possible ways to pass a  user agent string, and made the string artificially simple to avoid any mishaps. Using each one of these ways alone yields the same results.
The user-agent in the debug output is always Lavf.

I am useless as a C developer. The only workaround I could figure out is to hardcode the user-agent value in the file http.c and change line 132 from 
#define DEFAULT_USER_AGENT "Lavf/" AV_STRINGIFY(LIBAVFORMAT_VERSION)

to 

#define DEFAULT_USER_AGENT "Safari/" AV_STRINGIFY(LIBAVFORMAT_VERSION)

Luckily the server I am connecting to doesn't do any serious sanity checks on the user agent's name and version. 

This worked. But, (i) it's a stupid solution, and (ii) the next git pull will overwrite the hardcoded user-agent value.

Thank you for addressing this.

Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.

Change History (2)

comment:1 Changed 8 months ago by heleppkes

You need to pass options that refer to the input before the specification of the input parameter, so eg. this may work:

ffmpeg -user_agent Safari -i http://.......

comment:2 Changed 8 months ago by cehoyos

  • Component changed from ffmpeg to undetermined
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.