Why does send_file() require a path relative to pubdir?
Dancer::send_file() gives a "No such file" error if you pass it an absolute path or one that is not directly relative to $pubdir. I'm using send_file() to send dynamically generated PDF files to the client from behind pretty routes. That is, I want '/pdf/foo.pdf' to generate and send: /home/me/app/pdfbuild/foo-$user-$yymmdd-$hhmmss.pdf The generated PDF file has the user name in it so that other users don't clobber each others' generated PDFs. The file name contains a timestamp because the data that goes into the PDF changes frequently, so a second access of the URL needs to re-generate the PDF. Because of all this dynamic generation, I'm doing the background work in this pdfbuild directory, because I don't want to expose the intermediate files. I've fixed this by putting the intermediate files in pdfbuild and the final output PDF in .../pdfbuild/../public/pdf but this effectively exposes all generated PDFs: any user can pull up any other user's dynamic PDF if they know another user name and can make sensible guesses about the timestamp. Obviously I could add a nonce to the file name to make guessing impossible, but that's solving the symptom, rather than attacking the actual source of the problem. Why doesn't send_file() just return a binary blob to Dancer, which it recognizes and inserts literally into the response content body? Why does it care where on the filesystem that data comes from?
On Mon, 24 Mar 2014 07:55:45 -0600 Warren Young <warren@etr-usa.com> wrote:
Dancer::send_file() gives a "No such file" error if you pass it an absolute path or one that is not directly relative to $pubdir.
Use the system_path info, as documented, to indicate you're providing an absolute filesystem path. It's done this way to ensure users don't accidentally expose sensitive info from their systems. e.g.: send_file( "/home/me/app/pdfbuild/foo-$user-$yymmdd-$hhmmss.pdf", system_path => 1 ); (Obviously ensuring those vars are sane, and don't contain anything nefarious.)
On 3/24/2014 11:20, David Precious wrote:
On Mon, 24 Mar 2014 07:55:45 -0600 Warren Young <warren@etr-usa.com> wrote:
Dancer::send_file() gives a "No such file" error if you pass it an absolute path or one that is not directly relative to $pubdir.
Use the system_path info, as documented
D'oh!
(Obviously ensuring those vars are sane, and don't contain anything nefarious.)
Good point.
participants (2)
-
David Precious -
Warren Young