Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Aug 2, 2024
2 parents 715f716 + 2b3b8ed commit 7c0a539
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 34 deletions.
7 changes: 7 additions & 0 deletions contributing/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ You might get conflicts when you rebase. It is your
responsibility to resolve those locally, so that you can continue
collaborating with the shared repository.

Occasionally, the Composer packages for development may be updated. Run the
following command to use the latest packages:

```console
composer update
```

And finally push your local branch to your GitHub repository:

```console
Expand Down
12 changes: 0 additions & 12 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@
'count' => 1,
'path' => __DIR__ . '/system/BaseModel.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\BaseModel\\:\\:doErrors\\(\\) return type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/BaseModel.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\BaseModel\\:\\:doFind\\(\\) has parameter \\$id with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -5869,12 +5863,6 @@
'count' => 1,
'path' => __DIR__ . '/system/HTTP/ContentSecurityPolicy.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Property CodeIgniter\\\\HTTP\\\\ContentSecurityPolicy\\:\\:\\$validSources type has no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/HTTP/ContentSecurityPolicy.php',
];
$ignoreErrors[] = [
// identifier: codeigniter.superglobalAccess
'message' => '#^Accessing offset \'HTTP_USER_AGENT\' directly on \\$_SERVER is discouraged\\.$#',
Expand Down
4 changes: 2 additions & 2 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ abstract protected function doReplace(?array $row = null, bool $returnSQL = fals
* Grabs the last error(s) that occurred from the Database connection.
* This method works only with dbCalls.
*
* @return array|null
* @return array<string, string>
*/
abstract protected function doErrors();

Expand Down Expand Up @@ -1242,7 +1242,7 @@ public function replace(?array $row = null, bool $returnSQL = false)
*
* @param bool $forceDB Always grab the db error, not validation
*
* @return array<string,string>
* @return array<string, string>
*/
public function errors(bool $forceDB = false)
{
Expand Down
12 changes: 8 additions & 4 deletions system/HTTP/ContentSecurityPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ContentSecurityPolicy
/**
* CSP directives
*
* @var array<string, string>
* @var array<string, string> [name => property]
*/
protected array $directives = [
'base-uri' => 'baseURI',
Expand Down Expand Up @@ -166,7 +166,8 @@ class ContentSecurityPolicy
protected $sandbox = [];

/**
* Used for security enforcement
* A set of endpoints to which csp violation reports will be sent when
* particular behaviors are prevented.
*
* @var string|null
*/
Expand All @@ -189,7 +190,7 @@ class ContentSecurityPolicy
/**
* Used for security enforcement
*
* @var array
* @var list<string>
*/
protected $validSources = [
'self',
Expand Down Expand Up @@ -242,7 +243,7 @@ class ContentSecurityPolicy

/**
* An array of header info since we have
* to build ourself before passing to Response.
* to build ourselves before passing to Response.
*
* @var array
*/
Expand Down Expand Up @@ -594,6 +595,9 @@ public function addPluginType($mime, ?bool $explicitReporting = null)
*
* @see http://www.w3.org/TR/CSP/#directive-report-uri
*
* @param string $uri URL to send reports. Set `''` if you want to remove
* this directive at runtime.
*
* @return $this
*/
public function setReportURI(string $uri)
Expand Down
13 changes: 13 additions & 0 deletions tests/system/HTTP/ContentSecurityPolicyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,19 @@ public function testReportURI(): void
$this->assertStringContainsString('report-uri http://example.com/csptracker;', $result);
}

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
public function testRemoveReportURI(): void
{
$this->prepare();
$this->csp->reportOnly(false);
$this->csp->setReportURI('');
$this->work();

$result = $this->getHeaderEmitted('Content-Security-Policy');
$this->assertStringNotContainsString('report-uri ', $result);
}

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
public function testSandboxFlags(): void
Expand Down
10 changes: 6 additions & 4 deletions user_guide_src/source/libraries/curlrequest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ if it's not already set:

.. literalinclude:: curlrequest/024.php

.. note:: ``form_params`` cannot be used with the ``multipart`` option. You will need to use one or the other.
.. note:: ``form_params`` cannot be used with the `multipart`_ option. You will need to use one or the other.
Use ``form_params`` for ``application/x-www-form-urlencoded`` request, and ``multipart`` for ``multipart/form-data``
requests.

Expand Down Expand Up @@ -306,13 +306,15 @@ multipart
=========

When you need to send files and other data via a POST request, you can use the ``multipart`` option, along with
the `CURLFile Class <https://www.php.net/manual/en/class.curlfile.php>`_. The values should be an associative array
of POST data to send. For safer usage, the legacy method of uploading files by prefixing their name with an `@`
the `CURLFile Class <https://www.php.net/manual/en/class.curlfile.php>`_.

The values should be an associative array
of POST data to send. For safer usage, the legacy method of uploading files by prefixing their name with an ``@``
has been disabled. Any files that you want to send must be passed as instances of CURLFile:

.. literalinclude:: curlrequest/028.php

.. note:: ``multipart`` cannot be used with the ``form_params`` option. You can only use one or the other. Use
.. note:: ``multipart`` cannot be used with the `form_params`_ option. You can only use one or the other. Use
``form_params`` for ``application/x-www-form-urlencoded`` requests, and ``multipart`` for ``multipart/form-data``
requests.

Expand Down
10 changes: 6 additions & 4 deletions user_guide_src/source/libraries/curlrequest/028.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

$post_data = [
'foo' => 'bar',
'userfile' => new \CURLFile('/path/to/file.txt'),
];
$client->request('POST', '/post', [
'multipart' => [
'foo' => 'bar',
'userfile' => new \CURLFile('/path/to/file.txt'),
],
]);
4 changes: 4 additions & 0 deletions user_guide_src/source/libraries/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ the validation rules.
.. literalinclude:: validation/045.php
:lines: 2-

.. _saving-validation-rules-to-config-file:

Saving Sets of Validation Rules to the Config File
==================================================

Expand Down Expand Up @@ -875,6 +877,8 @@ Or you can use the following parameters:
.. literalinclude:: validation/047.php
:lines: 2-

.. _validation-available-rules:

***************
Available Rules
***************
Expand Down
27 changes: 19 additions & 8 deletions user_guide_src/source/models/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ $validationRules

Contains either an array of validation rules as described in :ref:`validation-array`
or a string containing the name of a validation group, as described in the same section.
Described in more detail below.
See also :ref:`model-setting-validation-rules`.

$validationMessages
^^^^^^^^^^^^^^^^^^^

Contains an array of custom error messages that should be used during validation, as
described in :ref:`validation-custom-errors`. Described in more detail below.
described in :ref:`validation-custom-errors`. See also :ref:`model-setting-validation-rules`.

$skipValidation
^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -661,11 +661,14 @@ Cleans out the database table by permanently removing all rows that have 'delete
In-Model Validation
===================

.. warning:: In-Model validation is performed just before data is stored in the
database. Prior to that point, the data has not yet been validated. Processing
user-input data prior to validation may introduce vulnerabilities.

Validating Data
---------------

For many people, validating data in the model is the preferred way to ensure the data is kept to a single
standard, without duplicating code. The Model class provides a way to automatically have all data validated
The Model class provides a way to automatically have all data validated
prior to saving to the database with the ``insert()``, ``update()``, or ``save()`` methods.

.. important:: When you update data, by default, the validation in the model class only
Expand All @@ -680,16 +683,24 @@ prior to saving to the database with the ``insert()``, ``update()``, or ``save()
To avoid such glitches, this behavior can be changed by configuration. See
:ref:`clean-validation-rules` for details.

.. _model-setting-validation-rules:

Setting Validation Rules
------------------------

The first step is to fill out the `$validationRules`_ class property with the fields and rules that should
be applied. If you have custom error message that you want to use, place them in the `$validationMessages`_ array:
The first step is to fill out the `$validationRules`_ class property with the
fields and rules that should be applied.

.. note:: You can see the list of built-in Validation rules in :ref:`validation-available-rules`.

If you have custom error message that you want to use, place them in the `$validationMessages`_ array:

.. literalinclude:: model/027.php

If you'd rather organize your rules and error messages within the Validation configuration file, you can do that
and simply set `$validationRules`_ to the name of the validation rule group you created:
If you'd rather organize your rules and error messages within the
:ref:`Validation Config File <saving-validation-rules-to-config-file>`, you can
do that and simply set `$validationRules`_ to the name of the validation rule
group you created:

.. literalinclude:: model/034.php

Expand Down

0 comments on commit 7c0a539

Please sign in to comment.