How can I limit access for automatically generated files to specific users in a MVC setup?

I have a typical MVC based website, and I’d like to give some registered users the abillity to extract data from the database (in a variety of formats). The workflow is very simple:

  • User logs in,
  • User clicks export,
  • A file is generated,
  • User downloads the file.

I’m trying to figure out a way to secure the last step and limit access to the file. In order for the user to be able to download the file, it should be in a publicly accessible folder. That, however, means that the file is accesible to everyone else that has access to its full url.

I thought of a few possible solutions:

  1. Email the export file

    Instead of having the user download the file, I could simply email it to their email (the one they used to register on the site). This seems like a decent option when the export files are small, but I don’t think it’ll be optimal for larger files.

  2. .htaccess magic

    I could automagically generate an .htaccess in the export dir that would only let the user who requested the export access it. Also a decent option, but it’s webserver specific and IP based. I don’t know if Apache will always be the webserver of choice for the project, and I’m not sure an IP based solution is actually secure.

  3. Store the export file in a private folder and have the user fetch it through ftp

    Secure, but not particularly user friendly.

All my options seem to have problems, and I’m at that point where I’m completely stuck and can’t shake the feeling I’m missing something obvious. Am I? Is there a better workflow?

I’m more interested in a high level overview than technical details, the project is still in its early days and technical requirements haven’t yet stabilized (e.g. we may not use Apache after all). The project is build in PHP, but I don’t think that matters (does it?).

Thanks.

You could serve the file via your PHP script, which checks if the user is authentificated.

E.g. pseudocode

if session.user is loggedIn
    filename = url.filename
    if filename belongs to session.user
        fetchfile(filename)
    else
        "you are not authorized to download this file"
else
    "please log in"

so only the user requested the export is able to download it. If another user gets the url he cannot download anything.

Don’t generate a file prior to authorizing request. This might be an expensive operation. First make sure that user has the necessary permissions and then generate files accordingly.

Since you are generating files on the fly, why store them? Can you not just serve files through response object and forget about them?

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

How can I limit access for automatically generated files to specific users in a MVC setup?

I have a typical MVC based website, and I’d like to give some registered users the abillity to extract data from the database (in a variety of formats). The workflow is very simple:

  • User logs in,
  • User clicks export,
  • A file is generated,
  • User downloads the file.

I’m trying to figure out a way to secure the last step and limit access to the file. In order for the user to be able to download the file, it should be in a publicly accessible folder. That, however, means that the file is accesible to everyone else that has access to its full url.

I thought of a few possible solutions:

  1. Email the export file

    Instead of having the user download the file, I could simply email it to their email (the one they used to register on the site). This seems like a decent option when the export files are small, but I don’t think it’ll be optimal for larger files.

  2. .htaccess magic

    I could automagically generate an .htaccess in the export dir that would only let the user who requested the export access it. Also a decent option, but it’s webserver specific and IP based. I don’t know if Apache will always be the webserver of choice for the project, and I’m not sure an IP based solution is actually secure.

  3. Store the export file in a private folder and have the user fetch it through ftp

    Secure, but not particularly user friendly.

All my options seem to have problems, and I’m at that point where I’m completely stuck and can’t shake the feeling I’m missing something obvious. Am I? Is there a better workflow?

I’m more interested in a high level overview than technical details, the project is still in its early days and technical requirements haven’t yet stabilized (e.g. we may not use Apache after all). The project is build in PHP, but I don’t think that matters (does it?).

Thanks.

You could serve the file via your PHP script, which checks if the user is authentificated.

E.g. pseudocode

if session.user is loggedIn
    filename = url.filename
    if filename belongs to session.user
        fetchfile(filename)
    else
        "you are not authorized to download this file"
else
    "please log in"

so only the user requested the export is able to download it. If another user gets the url he cannot download anything.

Don’t generate a file prior to authorizing request. This might be an expensive operation. First make sure that user has the necessary permissions and then generate files accordingly.

Since you are generating files on the fly, why store them? Can you not just serve files through response object and forget about them?

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

How can I limit access for automatically generated files to specific users in a MVC setup?

I have a typical MVC based website, and I’d like to give some registered users the abillity to extract data from the database (in a variety of formats). The workflow is very simple:

  • User logs in,
  • User clicks export,
  • A file is generated,
  • User downloads the file.

I’m trying to figure out a way to secure the last step and limit access to the file. In order for the user to be able to download the file, it should be in a publicly accessible folder. That, however, means that the file is accesible to everyone else that has access to its full url.

I thought of a few possible solutions:

  1. Email the export file

    Instead of having the user download the file, I could simply email it to their email (the one they used to register on the site). This seems like a decent option when the export files are small, but I don’t think it’ll be optimal for larger files.

  2. .htaccess magic

    I could automagically generate an .htaccess in the export dir that would only let the user who requested the export access it. Also a decent option, but it’s webserver specific and IP based. I don’t know if Apache will always be the webserver of choice for the project, and I’m not sure an IP based solution is actually secure.

  3. Store the export file in a private folder and have the user fetch it through ftp

    Secure, but not particularly user friendly.

All my options seem to have problems, and I’m at that point where I’m completely stuck and can’t shake the feeling I’m missing something obvious. Am I? Is there a better workflow?

I’m more interested in a high level overview than technical details, the project is still in its early days and technical requirements haven’t yet stabilized (e.g. we may not use Apache after all). The project is build in PHP, but I don’t think that matters (does it?).

Thanks.

You could serve the file via your PHP script, which checks if the user is authentificated.

E.g. pseudocode

if session.user is loggedIn
    filename = url.filename
    if filename belongs to session.user
        fetchfile(filename)
    else
        "you are not authorized to download this file"
else
    "please log in"

so only the user requested the export is able to download it. If another user gets the url he cannot download anything.

Don’t generate a file prior to authorizing request. This might be an expensive operation. First make sure that user has the necessary permissions and then generate files accordingly.

Since you are generating files on the fly, why store them? Can you not just serve files through response object and forget about them?

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật