
Please have a look at: https://cheatsheetseries.owasp.org/ and especially: https://cheatsheetseries.owasp.org/chea ... Sheet.htmlIt is written using PHP8, no framework and rely on some classes such as PHPMailer and PHPDotenv. Written from scratch as an occasion to actually learn PHP.
File storage and access can be a bigger threat, then storing it in a DB. Also, if the project is getting bigger, handling DB records is easier then a lot of files.The form takes the firstname, secondname, zipcode, e-mail (for answers) and a message, you can ask to receive a copy of the e-mail in your own mailbox and you have to validate our rules by checking a box before trying to send it. If everything is good (type of data for each field, length, etc), then the mail is stored for about X minutes, in a .json format, before a cron task send it. This cron task call a .php file that is using PHPMailer to send the e-mail with our SMTP server we pay for. The mails are send only one at a time, I'll give more details about it later on in this topic.
More visibilty, the greater the attack surface.This is a web mail form that'll go public this year if everything is ready for.
You are dealing with multiple attack vectors. Make sure you can handle them all. Securing a web application is only a small part of runnuing everything on your own.The server hosting is managed by me at home, on my own computer, on Gentoo with an hardened kernel. I try to take great care of the state and security of this machine. Firewall, keeping a eye on everything, trying to automate the process of keeping it alive, updating it very often and trying as much as I can to run only what's needed to me and my hosted sites. Nothing professional of course.
Where is this from? I didn't notice it in the owasp links, nor PHPMailer's github page (seemingly their primary site?).Banana wrote:The form takes the firstname, secondname, zipcode, e-mail (for answers) and a message, you can ask to receive a copy of the e-mail in your own mailbox and you have to validate our rules by checking a box before trying to send it. If everything is good (type of data for each field, length, etc), then the mail is stored for about X minutes, in a .json format, before a cron task send it. This cron task call a .php file that is using PHPMailer to send the e-mail with our SMTP server we pay for. The mails are send only one at a time, I'll give more details about it later on in this topic.
I do think you missed something to quote? What you quote is from kgdrenefortpjp wrote:Where is this from? I didn't notice it in the owasp links, nor PHPMailer's github page (seemingly their primary site?).Banana wrote:The form takes the firstname, secondname, zipcode, e-mail (for answers) and a message, you can ask to receive a copy of the e-mail in your own mailbox and you have to validate our rules by checking a box before trying to send it. If everything is good (type of data for each field, length, etc), then the mail is stored for about X minutes, in a .json format, before a cron task send it. This cron task call a .php file that is using PHPMailer to send the e-mail with our SMTP server we pay for. The mails are send only one at a time, I'll give more details about it later on in this topic.
Code: Select all
init=/sbin/openrc-init
-systemd -logind -elogind seatdI am NaN! I am a man!

The monthly fee hurts a bit to be honest, but that is still a very good kind of link I want in my bookmarks, thanks!grknight wrote:I recommend to try Freindly CAPTCHA which works by using the browser to do things to verify if it is a person or not. They are always updating it and based in Europe and GDPR compliant.
Ouch it hurts !pietinger wrote:Moved from Gentoo Chat to Networking & Security.
I know by experience that crawling bot could easily hit it. A good example is our half-open forum: I did made a mistake for non-registered users, I was sure you could not post. Seems the interface wasn't explaining this to me well enough (can't be me ! :P) and we had a wave of bots attacks. Not much, closed the forum the time to ban that and fix my mistakes.Banana wrote:There is no silver bullet and you can not create the a solution for cases you do not have (yet).
First, try to get to know your threat and prepare for that. And only for that. New threats will come and will need future solutions.
It was at first one of my goal but after some search it seems I have not the skill and also this is probably not the best idea. If I'm not good enough to manage the RFC and workflow of mails it is indeed safer to rely on PHPMailer which seems to be very well working in our conditions so far in my tests.Banana wrote:Also, do not re-event the wheel. PHPMailer is a good start.
Literally, for now, I just store .json file as this:Banana wrote:File storage and access can be a bigger threat, then storing it in a DB. Also, if the project is getting bigger, handling DB records is easier then a lot of files.
Code: Select all
{
"firstname": "K\u00e9vin",
"secondname": "GASPARD DE RENEFORT",
"email": "xxx@koshie.fr",
"zipcode": "75012",
"subject_prefix_list": "demande_renseignement",
"body": "Ce sujet est valide.\r\n\r\nCe texte est assez long pour pouvoir passer le nombre minimum de caract\u00e8res, car il est assez long, simple, non ?\r\n\r\nCependant, il est \u00e0 not\u00e9 qu'il est int\u00e9ressant de tester ce champ avec plusieurs lignes, s\u00e9par\u00e9 par un retour \u00e0 la ligne.",
"IP": "192.168.1.254",
"date_and_time": "2025-05-31_110432",
"send_copy": false
}And we get more and more popular slowly.Banana wrote:More visibilty, the greater the attack surface.
That's why I'm a bit paranoid.Banana wrote:You are dealing with multiple attack vectors. Make sure you can handle them all. Securing a web application is only a small part of runnuing everything on your own.
It seems my code handles it pretty well, for now.Banana wrote:I can only second the mentioned Friendly captcha solution grknight mentioned. But it will not stop any spam from "valid" users. It does not check the content of the data.
That is in my list of things to do for this case.Banana wrote:Use a csrf token
Did not done that in a while, will do.Banana wrote:Read about php_value post_max_size and php_value upload_max_filesize
Will do thanks.Banana wrote:Take a look at: https://perishablepress.com/7g-firewall/
In my opinion, this is wrong. You only validate a very small amount of things, in my 2088 cases only 16 cases are leading to an actual mail sending.Banana wrote:Check for what you want. NOT for what you do not want.
This is also in my list.Banana wrote:You can also limit the number of posts from that user/cookie (throttling), which can prevent certain forms of automated abuse.
The code is already available on my github. If I did not pushed it yet it's because the code base wasn't update for at least 3 months, because these last 3 months were 100% about my tests cases. Once they are ready, this week-end or next week, I would be able to update my code base with a sets of tests.Banana wrote:If you plan to make your code public and want some feedback, just let me know.
Yes I see that yesterday and very glad to have found it, I will take a look at it because it seems to almost do what could Cloudflare for bots, but self-hosted, as a free software… Looks very cool !Zucca wrote:I've seen some sites using Anubis for bot detection. I don't have any personal experience of using it.
Why? In ‘Gentoo Chat’ sometimes unimportant topics can be dealt with, while in ‘Networking & Security’ only deals with really important topics. You were careful and ‘just’ threw it into the chat. But it is important and then I have to ‘upgrade’ it.kgdrenefort wrote:Ouch it hurts !pietinger wrote:Moved from Gentoo Chat to Networking & Security.
That are a lot of testcaseskgdrenefort wrote:In my opinion, this is wrong. You only validate a very small amount of things, in my 2088 cases only 16 cases are leading to an actual mail sending.
If you don't check for things you want to avoid, how can you be sure your code reject what it is supposed to ?

If you check for what you want/expect, then everything else is rejected.kgdrenefort wrote:
In my opinion, this is wrong. You only validate a very small amount of things, in my 2088 cases only 16 cases are leading to an actual mail sending.Banana wrote: wrote:
Check for what you want. NOT for what you do not want.

That is very interesting, I would have to test that.Hu wrote:Regarding Anubis, I have a small bit of experience using it as an end user. Specifically, I have a zero percent success rate getting into sites that have decided to hide their content behind it, because the one time I unblocked enough scripts to get it to run, it used up far too much CPU time. Most (all?) such sites don't even provide proper contact information to report the problem, so I'm just slowly losing access to things as sites lock up their content behind it. It's very frustrating.
Not if you test everything, I could show you in more details (and share here) my testing scenario, I've hit +8k cases, a lot of it is covered.NeddySeagoon wrote: If you check for what you want/expect, then everything else is rejected.
When you check for what you don't want/expect, its easy to miss something.
No worry, merely joking.pietinger wrote:Why? In ‘Gentoo Chat’ sometimes unimportant topics can be dealt with, while in ‘Networking & Security’ only deals with really important topics. You were careful and ‘just’ threw it into the chat. But it is important and then I have to ‘upgrade’ it.
Indeed, a lot.Banana wrote:That are a lot of testcases :-)
Example:
If you want to make sure that an input is a number and a number only. You can try to start to check for all the chars you can think of which are NOT part of a number. And you will still miss some.
So do it the other way around. Since the input is a string, replace/remove everything which is a digit. If something is left (string is not empty/null), you are sure that the input has other chars than digits you do not want.

I'm confident that you won't do that. It's effectively saying that you are cleverer than all your attackers put together.kgdrenefort wrote:Not if you test everything, ...

By everything, I mean everything an user should be able to do, or a bot acting like an user, by trying to tweak and find any issue in the testing of one of my field.NeddySeagoon wrote:kgdrenefort,
I'm confident that you won't do that. It's effectively saying that you are cleverer than all your attackers put together.kgdrenefort wrote:Not if you test everything, ...
That is unlikely.