|
36 | 36 | * - {@see Sort::only()} ignores user-specified order for logical fields that have no configuration. |
37 | 37 | * - {@see Sort::any()} uses user-specified logical field name and order directly for fields that have no configuration. |
38 | 38 | * |
| 39 | + * Use {@see Sort::only()} by default, especially for user input. With {@see Sort::any()}, validate untrusted field names |
| 40 | + * against the fields your application allows before setting the order. Unchecked field names can lead to SQL injection |
| 41 | + * when used with a database-backed reader. |
| 42 | + * |
39 | 43 | * @psalm-type TOrder = array<string, "asc"|"desc"> |
40 | 44 | * @psalm-type TSortFieldItem = array<string, int> |
41 | 45 | * @psalm-type TConfigItem = array{asc: TSortFieldItem, desc: TSortFieldItem, default: "asc"|"desc"} |
@@ -131,6 +135,8 @@ private function __construct(private bool $ignoreExtraFields, array $config) |
131 | 135 | /** |
132 | 136 | * Create a sort instance that ignores the current order for extra logical fields that have no configuration. |
133 | 137 | * |
| 138 | + * Recommended by default, especially for user input. Define the allowed logical fields in application code. |
| 139 | + * |
134 | 140 | * @param array $config Logical fields config. |
135 | 141 | * @psalm-param TUserConfig $config |
136 | 142 | * |
@@ -173,6 +179,10 @@ public static function only(array $config): self |
173 | 179 | /** |
174 | 180 | * Create a sort instance that uses logical field itself and direction provided when there is no configuration. |
175 | 181 | * |
| 182 | + * The configuration is not an allowlist. Before passing untrusted input to {@see withOrder()} or |
| 183 | + * {@see withOrderString()}, validate field names against the fields your application allows. Unchecked field names |
| 184 | + * can lead to SQL injection when used with a database-backed reader. Prefer {@see only()} for user input. |
| 185 | + * |
176 | 186 | * @param array $config Logical fields config. |
177 | 187 | * @psalm-param TUserConfig $config |
178 | 188 | * |
|
0 commit comments