bugs unauthorized users access pdf files knowing the link
Re: bugs unauthorized users access pdf files knowing the link
Hi facos,
I just saw your posting by accident.
as this thread holds actually more than one solution, maybe you could exactly pinpoint which solution you are using - thus which one is not working (anymore for you).
The last solution is using standard AG libraries and login-check. If the script IS broken, I suppose it should be quite easy to fix as the rest is very simple and does not reply on AG but Apache and basic htaccess.
Olaf
I just saw your posting by accident.
as this thread holds actually more than one solution, maybe you could exactly pinpoint which solution you are using - thus which one is not working (anymore for you).
The last solution is using standard AG libraries and login-check. If the script IS broken, I suppose it should be quite easy to fix as the rest is very simple and does not reply on AG but Apache and basic htaccess.
Olaf
Some postings I was involved, you might find useful:
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Re: bugs unauthorized users access pdf files knowing the link
Hello,
the solution that no longer works is the following:
e
I think that, nowadays, appgini should protect themselves without additional codes all the folders where photos and documents are saved. The function is essential for the apps created to be safe. Unfortunately, those who do not know how to program rely on software as appgini to be able to realize what would be impossible to achieve. The safety of the finished product is essential. In this case the folder containing the uploads can be accessed by knowing the download link. It should be blocked from unwanted access and above all from access by users who are not logged in.
I find Appgini to be great software and I hope a security solution will be integrated in the future.
the solution that no longer works is the following:
Code: Select all
RewriteEngine on
RewriteRule .* protect.php
Code: Select all
<?php
define('PREPEND_PATH', '../');
$hooks_dir = dirname(__FILE__);
include("$hooks_dir/../defaultLang.php");
include("$hooks_dir/../language.php");
include("$hooks_dir/../lib.php");
/* grant access to the groups 'Admins' and 'Other'*/
$mi = getMemberInfo();
if(!in_array($mi['group'], array('Admins', 'Other'))){
header("location: /");
exit;
} else {
//Check if user has right to access the file. If no, show access denied and exit the script.
$path = $_SERVER['REQUEST_URI'];
$paths = explode('/', $path);
$lastIndex = count($paths) - 1;
$fileName = $paths[$lastIndex];
header('Content-type: application/pdf');
header("Content-Disposition: inline; filename=$fileName");
readfile($fileName);
}
I find Appgini to be great software and I hope a security solution will be integrated in the future.
Re: bugs unauthorized users access pdf files knowing the link
Hi,
maybe your provider changed something (Apache version). Try the other .htaccess which I have shown here (this thread): viewtopic.php?f=11&t=2856#p15242
Maybe this does the trick already.
Also it might help to see what happens internally so, why the permissions check fails. You should try to enable php error reporting. Just google how to do it (example: https://phoenixnap.com/kb/php-error-reporting ). Afterwards access a file in the "protected" folder and see if any errors occur.
Olaf
maybe your provider changed something (Apache version). Try the other .htaccess which I have shown here (this thread): viewtopic.php?f=11&t=2856#p15242
Maybe this does the trick already.
Also it might help to see what happens internally so, why the permissions check fails. You should try to enable php error reporting. Just google how to do it (example: https://phoenixnap.com/kb/php-error-reporting ). Afterwards access a file in the "protected" folder and see if any errors occur.
Olaf
Some postings I was involved, you might find useful:
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Re: bugs unauthorized users access pdf files knowing the link
PHP 7.4 it works, everything seems to work very well with 7.4
Seems I am stuck with 7.4 for a while, protecting files is essential.
PHP 8.1.4 does not work, 8.0+ is giving me headaches!
Seems I am stuck with 7.4 for a while, protecting files is essential.
PHP 8.1.4 does not work, 8.0+ is giving me headaches!
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper
Re: bugs unauthorized users access pdf files knowing the link
Hi,
it doesn't work for me anymore with a newer PHP version either.
Does anyone have another solution to protect the directory with the documents?
Thank you very much,
Kai
it doesn't work for me anymore with a newer PHP version either.
Does anyone have another solution to protect the directory with the documents?
Thank you very much,
Kai
Re: bugs unauthorized users access pdf files knowing the link
HI,
unfortunately I have a problem:
the code works correctly and blocks the opening of images or documents if the user is not logged in.
But I can't view the images when I click on them to enlarge them (see attached photo).
I use the latest version of appgini 24.12 revision 1612 and version PHP Version 8.3.3.
How can I solve the problem?
The documents, however, since they do not have a preview, are downloaded regularly.
Thanks for your help
unfortunately I have a problem:
the code works correctly and blocks the opening of images or documents if the user is not logged in.
But I can't view the images when I click on them to enlarge them (see attached photo).
I use the latest version of appgini 24.12 revision 1612 and version PHP Version 8.3.3.
How can I solve the problem?
The documents, however, since they do not have a preview, are downloaded regularly.
Thanks for your help
onoehring wrote: ↑2020-06-22 06:08Hi Zala,
I do not understand. In my post above ( viewtopic.php?p=13800#p11378 ) there the script checks the filetype and arranges the header for download as needed.
Besides, the original ( posting.php?mode=reply&f=11&t=2856#pr9355 ) should work for all filetypes anyways - just giving a wrong header - which I believe - the browser will correct (and allow access to the file if the user is logged in).
You may try to remove the two header lineswhich should download an unspecified filetype.Code: Select all
header('Content-type: application/pdf'); header("Content-Disposition: inline; filename=$fileName");
Or ... try a combination of both:
protect.php (not tested):OlafCode: Select all
<?php //initial source: https://forums.appgini.com/phpbb/viewtopic.php?t=2856#p9355 // version: 2019-10-29 15:00:00 (adjusted for admin group 2020-06-22) // Olaf Noehring, https://datenbank-projekt.de define('PREPEND_PATH', '../'); $hooks_dir = dirname(__FILE__); include("$hooks_dir/../defaultLang.php"); include("$hooks_dir/../language.php"); include("$hooks_dir/../lib.php"); /* grant access to the groups 'Admins' and 'Other'*/ $mi = getMemberInfo(); if(!in_array($mi['group'], array('Admins', 'Other'))){ header("location: /"); exit; } else { $path = $_SERVER['REQUEST_URI']; $paths = explode('/', $path); $lastIndex = count($paths) - 1; $fileName = $paths[$lastIndex]; $extension = strtolower(substr(strrchr($path, "."), 1)); $fname = __DIR__."/".$fileName; switch ($extension){ case "pdf": header('Content-type: application/pdf'); break; case "jpg": header('Content-Type: image/jpeg'); break; case "jpeg": header('Content-Type: image/jpeg'); break; case "png": header('Content-Type: image/png'); break; default: header('Content-type: application/pdf'); } header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($fname)).' GMT', true, 200); header('Content-Length: '. filesize($fname)); header("Content-Disposition: attachment; filename=\"" .$fileName. "\""); readfile($fileName); } ?>
- Attachments
-
- Screenshot 2024-05-01 162354.png (152.17 KiB) Viewed 3222 times
Re: bugs unauthorized users access pdf files knowing the link
Hi,
are you working on localhost? I think I remember, that there could be a problem on localhost, which does not exist on a "real" server.
Olaf
are you working on localhost? I think I remember, that there could be a problem on localhost, which does not exist on a "real" server.
Olaf
Some postings I was involved, you might find useful:
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Re: bugs unauthorized users access pdf files knowing the link
no, I'm on a hosting server.
If I delete the code from .htaccess and protect.php the image opens normally.
If I delete the code from .htaccess and protect.php the image opens normally.
Re: bugs unauthorized users access pdf files knowing the link
Hi,
currently I am having a similar problem with the zoom of images (see viewtopic.php?f=2&t=5364 ). i believe yours and mine could be connected somehow. I will let you know if I find the problem ... which I really need to solve.
Olaf
currently I am having a similar problem with the zoom of images (see viewtopic.php?f=2&t=5364 ). i believe yours and mine could be connected somehow. I will let you know if I find the problem ... which I really need to solve.
Olaf
Some postings I was involved, you might find useful:
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Re: bugs unauthorized users access pdf files knowing the link
I absolutely agree!
Protection of uploaded files, uploaded via built-in upload feature into default
/images
folder (or configured upload-dir), should be built-in, in my opinion.Just a suggestion:
Did you send a feature request to BigProf, yet, proposing a working solution?
From my experience Ahmed is open for bullet-proof code, suggested by community members, if this code does not break compatibility.
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 25.10 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 25.10 + all AppGini Helper tools
Re: bugs unauthorized users access pdf files knowing the link
Hi Jan,
actually I think I did request this feature already in November 2020: viewtopic.php?f=6&t=3989

Olaf
actually I think I did request this feature already in November 2020: viewtopic.php?f=6&t=3989

Olaf
Some postings I was involved, you might find useful:
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Re: bugs unauthorized users access pdf files knowing the link
Just wondering: Did one of you send tested code to BigProf as a feature-request for a future version or is it just an article for our community? I doubt (and I'm glad) BigProf will integrate everything posted here.
It's just my personal experience that Ahmed is willing to integrate our contributions if we give well tested code to him which does not break backward compatibility nor has negative impact on exitlsting installations.
It's just my personal experience that Ahmed is willing to integrate our contributions if we give well tested code to him which does not break backward compatibility nor has negative impact on exitlsting installations.
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 25.10 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 25.10 + all AppGini Helper tools
Re: bugs unauthorized users access pdf files knowing the link
Hi,
I think I solved the problem facos79 described.
Please download the latest version here: https://url.olaf-noehring.de/agprotectuploadfolder (currently v2024-05-30)
Feedback appreciated. (I know, code may be ugly ... but if it works ...
)
Olaf
I think I solved the problem facos79 described.
Please download the latest version here: https://url.olaf-noehring.de/agprotectuploadfolder (currently v2024-05-30)
Feedback appreciated. (I know, code may be ugly ... but if it works ...

Olaf
Some postings I was involved, you might find useful:
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Re: bugs unauthorized users access pdf files knowing the link
Thank you!! This seems like a really good solution.
I'll try to apply it in the next few days and let you know.
Thanks again.
See you soon
I'll try to apply it in the next few days and let you know.
Thanks again.
See you soon