Skip to content

base64_decode: reject inputs with non-base64 characters (fail safely) #20187

@touchweb-vincent

Description

@touchweb-vincent

Description

Hello,

I’m fully aware that I’m raising an issue that isn’t directly caused by PHP itself. However, since we haven’t been able to find any viable technical solution that doesn’t either introduce or worsen a chain of erratic side effects - some minor, some not - I would truly appreciate it if you could give this matter some attention.

base64_decode currently accepts inputs containing characters outside the Base64 alphabet, which can trigger erratic behavior in downstream systems.

<?php echo base64_decode('P~.F$.~N~~Dc~.mlwd~Ao.+~IG~$FsZ.XJ0.K.D$c5Nik8L1$N$~D$cmlwdD.4~7$$');

It would be highly appreciated if this could fail loudly - ideally with a fatal error or exception - when the input is not strictly valid.

This behavior causes issues for security infrastructures and DevSecOps teams, as many systems downstream of PHP (WAFs, proxies, forensic tools) rely on strict decoding logic - unexpected input can cause failures, inconsistent behavior, or even crashes.

owasp-modsecurity/ModSecurity#3327

Thanks you

Vincent

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions