News for hackers. Stuff that matters.
Re:Simply Secure PHP Cryptography by stephenr on Thursday July 13, 2017 @02:14PM (#14763725)
Given how much has been deprecated/removed since 5.2, would you care to list some that remain?
Re:Simply Secure PHP Cryptography by bpicolo on Thursday July 13, 2017 @02:32PM (#14763887)
Silent failures for indexing on primitives?

$foo = 1; $foo[1]; // no problems

$foo = true; $foo[0]; // seems good to php

PHP's choose-your-own-error-adventure with all errors on (which is the only good choice) is pretty silly. arrays become somewhat unwieldy because the core libs for arrays are deficient, missing things like a get_default($array, $key, $default).

The array core lib in general is troublesome to understand/intuit different pieces for, probably because mashing hash types and lists together leads to all sorts of ambiguity (like ambiguous json decoding/encoding). Want some subset of an array? Sure, that's the super-intuitive `array_intersect_key($array, array_flip($keys));`

The core array type is really a frustrating experience in PHP, and interop deficiencies with ArrayObject make it unusable as an alternative.

Re:Simply Secure PHP Cryptography by stephenr on Thursday July 13, 2017 @02:45PM (#14763987)
> get_default($array, $key, $default).

$array[$key] ?? $default

im still not sure what any of this has to do with "the only secure php is no php"?

Re:Simply Secure PHP Cryptography by bpicolo on Thursday July 13, 2017 @02:49PM (#14764018)
With all notices on accessing an undefined index is a notice, which you're doing with that syntax, no?
Re:Simply Secure PHP Cryptography by aruggirello on Thursday July 13, 2017 @03:47PM (#14764544)
No notices - But this syntax has been introduced in 7.0. Old style is:

isset($array[$key]) ? $array[$key] : $default

Which is, admittedly, just a bit uglier.

Edit: isset() is a language construct, not a function call. So it does not incur performance penalties. The ?? operator was introduced for 'cosmetic' reasons only, so don't rush to update your source...

Re:Simply Secure PHP Cryptography by CiPHPerCoder on Thursday July 13, 2017 @02:50PM (#14764033)
Re:Simply Secure PHP Cryptography by bpicolo on Thursday July 13, 2017 @02:52PM (#14764053)
Ahh this is new in 7.0. Good to know, hadn't seen that. Still of the opinion that the array builtins are a hassle. =]
Re:Simply Secure PHP Cryptography by smt88 on Thursday July 13, 2017 @02:22PM (#14763812)
Truthiness (e.g. 0 == false, '0' == true, 'false' == true, etc.) makes it easier to introduce bugs. There's a lot of discipline/linting still required in PHP, whereas other languages won't even compile if you do something risky.

I wouldn't take that criticism too personally. People also argue that C/C++ can't ever be secure due to the ease of programmer mistakes.

Re:Simply Secure PHP Cryptography by CiPHPerCoder on Thursday July 13, 2017 @02:35PM (#14763908)
> Truthiness (e.g. 0 == false, '0' == true, 'false' == true, etc.) makes it easier to introduce bugs.

Use === instead; except for cryptography, where you want hash_equals().

> There's a lot of discipline/linting still required in PHP, whereas other languages won't even compile if you do something risky.

And/or just use scalar type declarations: https://3v4l.org/SJKe1

Re:Simply Secure PHP Cryptography by smt88 on Thursday July 13, 2017 @03:05PM (#14764188)
I agree that there are safe (or safer) ways to do things in PHP, but in business settings, it's often hard to enforce such things. "Discipline" is very hard to maintain consistently across people with different backgrounds.

I've actually gone as far as rejecting commits that failed the linter and style checker, but that only works for code bases I have control over. It doesn't apply to the libs.

I now prefer languages where the entire ecosystem is passing strict compilation requirements.

Re:Simply Secure PHP Cryptography by bpicolo on Thursday July 13, 2017 @02:38PM (#14763931)
Scalar type declarations don't help detect usage of undefined variables, as an example. Phan is the only tool I've found that does, but it's a very heavyweight thing, given how necessary it is to prevent undefined variable exceptions.
Re:Simply Secure PHP Cryptography by muglug on Thursday July 13, 2017 @02:43PM (#14763966)
I wrote a similar tool that's slightly less heavyweight (doesn't rely on a separate extension): https://getpsalm.org/
Re:Simply Secure PHP Cryptography by bpicolo on Thursday July 13, 2017 @02:55PM (#14764082)
I'm going to be trying it out. Thanks. The more lints the better when dealing with legacy monoliths!
Re:Simply Secure PHP Cryptography by CiPHPerCoder on Thursday July 13, 2017 @02:44PM (#14763976)
Yes, Psalm is great. We use it in a lot of our projects, and in the future will be using it in all of them. We absolutely love it. (It's on my "to blog about" queue.)
Re:Simply Secure PHP Cryptography by CiPHPerCoder on Thursday July 13, 2017 @02:39PM (#14763939)
That's a separate concern from truthiness. And if you aren't using nullable types (a 7.1+ feature), passing NULL gives you a TypeError. :)
Re:Simply Secure PHP Cryptography by masklinn on Thursday July 13, 2017 @03:48PM (#14764557)
> Truthiness (e.g. 0 == false, '0' == true, 'false' == true, etc.)

That's not truthiness, that's implicit coercions.

Truthiness is specific to boolean contexts (if, while, explicit conversion to boolean).

Re:Simply Secure PHP Cryptography by smt88 on Thursday July 13, 2017 @04:08PM (#14764719)
I guess that's an interesting nitpick, but I was referring to truthiness. I chose what I now see was a confusing way to express it as text.

What I really meant was that you have some $variable, and you test it in an if, while, etc. context. If the value is 0, it's false. But if you didn't realize you got a string from somewhere, it might be true. Unless it's an empty string? (I can't even remember.)

None of this changes the initial point, which is that writing "good" PHP requires enormous amounts of discipline, and that still doesn't address the security issues with PHP itself. I remember when the developer of Suhosin basically quit PHP and said he couldn't deal with the way its maintainers treated security issues.

Re:Simply Secure PHP Cryptography by TylerE on Thursday July 13, 2017 @03:08PM (#14764211)
That will be a valid rebuttal when ten million shitty shared hosts are no longer on 5.x - and probably an out of date 5.x at that.
Re:Simply Secure PHP Cryptography by function_seven on Thursday July 13, 2017 @03:12PM (#14764253)
Then you should rephrase your statement.

Something like:

    The only secure PHP is version x.x or newer.
Re:Simply Secure PHP Cryptography by TylerE on Thursday July 13, 2017 @03:16PM (#14764284)
I do not believe there to be an $x where that statement is true.
Re:Simply Secure PHP Cryptography by CiPHPerCoder on Thursday July 13, 2017 @03:18PM (#14764296)
Then your previous statement about PHP versions is irrelevant, and you should answer the question you were asked. To wit:

> Given how much has been deprecated/removed since 5.2, would you care to list some that remain?

For the version coming out at the end of the year, what is still insecure that leads you to believe "there is not an $x where that a statement is true"?

Re:Simply Secure PHP Cryptography by TylerE on Thursday July 13, 2017 @03:45PM (#14764525)
I don't see what's so hard to understand.

7.x is better than 5.x but not GOOD ENOUGH.

Re:Simply Secure PHP Cryptography by CiPHPerCoder on Thursday July 13, 2017 @03:46PM (#14764533)
> 7.x is better than 5.x but not GOOD ENOUGH.

What would make it good enough? Be specific.

Re:Simply Secure PHP Cryptography by ryanlol on Friday July 14, 2017 @01:17AM (#14767670)
I think we agree that the interpreter still isn't a paragon of secure programming practices :P
[dead]
Re:Simply Secure PHP Cryptography by root_axis on Thursday July 13, 2017 @04:44PM (#14765035)
Sounds like you have no specifics to back up what you're saying and just enjoy bashing PHP because that is the trendy thing to do. You were asked for specifics several times and all you can offer are snarky pejoratives, it reads like textbook trolling.
Re:Simply Secure PHP Cryptography by anotherbrownguy on Friday July 14, 2017 @01:14AM (#14767652)
I think the new trend is defending it.
Re:Simply Secure PHP Cryptography by root_axis on Friday July 14, 2017 @10:18AM (#14769963)
A defense implies an attack, so someone has to start bashing PHP before anyone has an opportunity to defend it, however, I don't regard asking for specifics as a defense.
Re:Simply Secure PHP Cryptography by ocra on Thursday July 13, 2017 @04:08PM (#14764714)
My stateless PHP projects are kinda enjoying the view over the GC and memleak hell happening on the other Java/NodeJS projects that I sadly have to deal with.
Re:Simply Secure PHP Cryptography by clowd on Thursday July 13, 2017 @04:09PM (#14764722)
Yeah, it's not like more than half of all websites run PHP, or anything...
Re:Simply Secure PHP Cryptography by smt88 on Thursday July 13, 2017 @04:19PM (#14764806)
Most are WordPress, and it's not like WordPress has had a smooth development history... It's one of the most-exploited entry points into a server. That's why anyone running a server for long enough will see tons of hits to their access logs looking to /wp-admin and other WP-specific URIs.