Download the PHP package yohgaki/validate-php-scr without Composer

On this page you can find all versions of the php package yohgaki/validate-php-scr. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package validate-php-scr

"Validate" for PHP - An INPUT data validation framework

CI

"Validate" is "input data validation framework" that is developed to be useful for "CERT Secure Coding" and "Design by Contract"(DbC). "Validate" is designed to develop OWASP TOP 10 A10:2017 vulnerability compliant application. "Validate" is planned to be implemented as C module for PHP.

CERT Top 10 Secure Coding Practices.

1. Validate input. Validate input from all untrusted data sources. Proper input validation can eliminate the vast majority of software vulnerabilities. Be suspicious of most external data sources, including command line arguments, network interfaces, environmental variables, and user controlled files [Seacord 05].

Validate for PHP is designed to help "Standard Input Validation".

Use a standard input validation mechanism to validate all input for:

  • length
  • type of input
  • syntax
  • missing or extra inputs
  • consistency across related fields
  • business rules

Basic Design

"Validate" is very flexible and able to perform any data validations, including HTTP header/Query parameter validations with multi stage validations, HTML form validations, JSON data validations, etc. Although "Validate" is designed to validate all inputs at once, you may validate values one by one also.

"Strings" are the most important for input validations and "Validate" is strict for string validations. Many apps miss to validate "char encodings" and "length". "Validate" forces them to be validated always by default. "Validate" does not allow Unicode control characters which cause problems by default.

Requirements

Recommended

Branches

Every branch provides the same features with code written for its PHP versions. Pick the branch for your PHP version.

Branch PHP CI (GitHub Actions)
master 8.0 and up, including versions in development 8.0 - 8.5, nightly, master CI
php-8.x 8.x 8.0 - 8.5 CI
php-7.x 7.0 - 7.4 7.0 - 7.4 CI
php-5.x 5.3 - 5.6 5.3 - 5.6 CI

Releases

Install with Composer: composer require yohgaki/validate-php-scr:^1.0. The same constraint works on every supported PHP version: each branch has its own release tags, and Composer installs the newest release whose php requirement your PHP meets.

Composer's vendor/autoload.php loads the procedural API (src/validate_func.php, which loads Validate.php and the constants). The predefined specs are a variable, so require them where you use them: require 'vendor/yohgaki/validate-php-scr/src/lib/basic_types.php'; defines $basicTypes. (Without Composer, require_once src/validate_func.php as in the examples.)

Basic Behaviors

Tip:

Character Encoding Validation

Every string that VALIDATE_STRING, VALIDATE_REGEXP or VALIDATE_CALLBACK accepts has its character encoding validated:

Transfer-encoded strings are decoded before the check. The 'transfer_encoding' option checks the encoded form strictly, decodes it, and validates the decoded text as above ('encoding', flags, RFC 3454, 'unicode'). 'min' / 'max' apply to the input as received, VALIDATE_REGEXP matches 'regexp' against it, VALIDATE_CALLBACK passes it to the callback, and the validated value is the input as received.

'transfer_encoding' Encoded form
quoted-printable RFC 2045 6.7: lines of at most 76 chars separated by CRLF; printable ASCII, SPACE and TAB, but no SPACE / TAB at the end of a line; = only in =XX (uppercase hex digits) or as a soft line break at the end of a line other than the last. A hard line break is CRLF in the decoded text.
percent The output of urlencode() / rawurlencode(): RFC 3986 unreserved chars, %XX and + (a space).
base64 / base64url RFC 4648 4 / 5. = padding is optional but must complete the last group; the unused bits of the last char must be zero.
html The output of htmlspecialchars($s, ENT_QUOTES): no raw < > " '; & only in &amp; &lt; &gt; &quot; &apos; or a numeric reference to U+0001 - U+10FFFF other than a surrogate. References are decoded after the conversion to UTF-8.

mbstring of each PHP version decides what is valid in each encoding. UTF-8 gives the same results on every supported PHP version: dev/mb_check.php compares mb_check_encoding() with the RFC 3629 grammar on 300,000 byte strings of 1 - 6 bytes, and they agreed on every PHP version from 5.4 to 8.7.0-dev; on PHP 5.3, mbstring also accepted 41 of them, all UTF-8 forms of values beyond U+10FFFF, which "Validate" itself rejects. Other encodings can differ between PHP versions. Measured with the same script on PHP 5.3 - 8.7.0-dev (October 2026):

Input validation is not output sanitization. "Validate" rejects input that is not valid; it never modifies input to make it valid (only a 'filter' the spec author sets normalizes input before validation), and it never uses an output function (escaping or sanitizing, e.g. htmlspecialchars()) to decide whether input is valid. Escape or sanitize data where it is output, for that output. Input validation does not replace output sanitization, and output sanitization does not replace input validation.

Example #1: Single value validation with exception

src/examples/91-example.php

Validation error results in Exception. Application input data validation errors should be handled by exception without user interaction.

NOTE: Valid inputs are any inputs that the application is supposed to handle. i.e. Input mistakes are valid inputs for an application.

Example #2: Single value validation without exception

src/examples/92-example.php

Validation errors are stored in $ctx (they accumulate across calls on the same context, while validate_get_status() reflects the most recent call). Application business logic data validation errors should be handled without error/exception for interactive error handling.

Example #3: Multiple value validations at once.

src/examples/93-example.php

"Validate" removes validated elements from $inputs. You can validate remaining elements by next validation: pass VALIDATE_OPT_UNVALIDATED to every stage except the last, because input keys a spec does not declare are errors by default. To validate keys you cannot list in advance (e.g. HTTP headers) in the same call, use the "undeclared" option instead (Example #4).

A little more realistic working example is here:

Example #4: Validation that validates all HTTP headers

src/examples/94-example.php

Known headers get explicit specs; the "undeclared" option validates every other header with a catch-all spec, and VALIDATE_FLAG_ARRAY_KEY_ALNUM restricts their names.

OWASP TOP 10 A10:2017 requires to validate all inputs. Although you are better to do stricter validations against headers, this validation is OWASP TOP 10 A10:2017 compliant HTTP request header validation.

Example #5: Validate all HTTP inputs ($_GET / $_POST / $_COOKIE / $_FILES / headers) at once

src/examples/95-example.php

A realistic user-registration form receives data from multiple sources: a CSRF token in $_GET, the form fields in $_POST, a session identifier in $_COOKIE, an avatar upload in $_FILES, and the HTTP request headers. All of them are untrusted and must be validated. "Validate" can verify the entire request in a single validate() call by nesting per-source specs under one VALIDATE_ARRAY spec.

Key points:

"APPLICATION INPUT" and "BUSINESS LOGIC" Data Validation Basics

APPLICATION INPUT data validation and BUSINESS LOGIC data validation are 2 different validations.

APPLICATION INPUT Data Validation

IMPORTANT: User mistakes are valid inputs.

APPLICATION INPUT data should be validated as fast as it can to minimize misbehavior/vulnerability. Application INPUT data validation must validate all inputs are valid for the application. i.e. If ID is number between 1000 and INT_MAX, then you must only accepts number 1000 from INT_MAX. If a string is for names, then the string should never exceed 512 bytes unless attacker is tampering your application. If your application restricts name length to 100 by client side JavaScript, then you should never accept strings longer than 100. Do not forget to check too few/many parameters as this is one of a "standard input validation" requirement.

All of application input data must be validated and validations should be done at Application Trust Boundary. Application INPUT data validation assures "Values have correct forms". e.g. length, range, encoding, used chars, specific formats such as date, phone, zip. Both Correct and "Input mistake" values are valid input data.

Application INPUT data validation failure MUST NOT require user interactions. INPUT data validation failure means "A user sent Invalid values.(= values clients cannot/should not send. unacceptable values. e.g. Too large, broken char encoding, malformed format/char, etc). These invalid inputs MUST simply be rejected and handled according to "FAIL FAST" principle. i.e. Reject invalid inputs like WAF(Web Application Firewall) does. All inputs, including HTTP headers/query parameters, must be validated always.

Input data format correctness must be validated by server always AND the validation must be done as fast as it can. Input data validation should not require user interaction, should not provide meaningful error message (to attackers).

BUSINESS LOGIC Data Validation

IMPORTANT: Detecting broken/totally wrong/invalid inputs at business logic code is too late. It is good for "fail safe", but "fail safe" is not an ideal security measure.

BUSINESS LOGIC data validation is for input mistake detection that users allowed to, not for totally broken inputs sent from crackers. Business logic (e.g. Model in MVC) should not supposed to handle totally wrong input value (e.g. number is expected, but string is supplied) because totally wrong values should be handled by APPLICATION INPUT validation already.

Application BUSINESS LOGIC data validation validates values against business logic. e.g. Reservation date is future date, min value is less than max value, has valid CSRF token, etc. BUSINESS LOGIC data validations are responsible for logical correctness mainly.

Unlike Application INPUT data validations, many BUSINESS LOGIC data validations require user interactions to correct input mistakes.

Logical data correctness must be validated by server always. Business logic validation usually requires user interaction and/or should provide meaningful error message what went wrong.

References

Documents

Reference.

Examples.

Codes.

Status

TODO

Input Data Security Tip

Strings are the most risky inputs and web apps are made by string inputs. i.e. Almost all inputs to web apps are strings. Invalid strings must not be processed by web apps' code at all.

While most web apps do not validate input string character encoding, web developers must validate character encodings. If you don't validate character encoding, your application became vulnerable to DoS easily. i.e. htmlspecialchars() return empty string, modern browsers refuse to render badly broken encoding, system has both binary safe and encoding aware APIs/storages. These facts create very hard to find DoS vulnerabilities.

In order to programs to work correctly, valid data is absolute mandatory requirement. Invalid data for program results in invalid state always.

Some apps/libraries sanitize input data and make "invalid data" into "valid data" because "valid data" is mandatory. However sanitization ignores and hides attacks from cyber criminals. Ignoring and hiding attacks is insecure practice should be avoided. Developers must not rely on sanitizer in general.

Extending

Since "Validate" is designed as framework, it is easy to extend. It can work with other validators such as Respect.

"src/tools" directory contains tools that request logging, creating validation spec rules from log and validation script.

"Validate" C extension module

This PHP script is based on validate C module for PHP 7. Features are planned to be ported to C module which can perform validations a lot faster.

https://github.com/yohgaki/validate-php (Do not use this. Use PHP script version for now.)

Comments & Issues

Comments, Bug reports and PRs are welcomed! Please remember "Validate" is not optimized for OO nor PHP scripts, but C module. This script is planned to be implemented as a C module in the future.


All versions of validate-php-scr with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yohgaki/validate-php-scr contains the following files

Loading the files please wait ...