Commit graph

122 commits

Author SHA1 Message Date
MDW
a0b820564f
QUAL: Add SqlInjectionPlugin to detect unsafe SQL variable usage (fixes, notices) (#38722)
* QUAL: Add SqlInjectionPlugin to detect unsafe SQL variable usage

# QUAL: Add SqlInjectionPlugin to detect unsafe SQL variable usage

This commit adds a new SqlInjectionPlugin to the Phan configuration, which helps detect unsafe SQL variable usage in the Dolibarr codebase. The plugin checks for variables used in sql expressions that are not properly escaped, cast, or protected by safe methods.

* Qual: Add SqlInjection exceptions to Phan baseline

* Qual: Add SqlInjection exceptions to Phan baseline

* Qual: Update baseline.txt to remove SqlInjection suppressions

The SqlInjection suppressions have been removed from the baseline.txt file.
This reenables the notification of "unfixed" cases.

* Qual: SQL injection detection for missing quotes on escaped strings

# Qual: SQL injection detection for missing quotes on escaped strings

In summary: report lines with missing quotes as in `" WHERE ".$db->escape($value)." OR "`.

* Qual: Fix code for SqlInjection analysis

# Qual: Fix code for SqlInjection analysis

Rewrite some escape calls, change escape() in sanitize(), rename variable, ignore SqlInjection notices.

* Qual: Update baseline

Allow some SqlInjection* notices, to be fixed later or already fixed in develop.
2026-08-08 11:19:04 +02:00
MDW
cec87d9425
Qual: Remove unnecessary quotes around integer values in SQL queries (#39290)
* FIX: Do not quote NULL for fk_user_author & fk_element on insert

* Qual: Remove unnecessary quotes around integer values in SQL queries

# Qual: Remove unnecessary quotes around integer values in SQL queries

Removed unnecessary single quotes around integer values in SQL queries across multiple files.
2026-07-27 12:59:14 +02:00
MDW
1dcd497c69
Qual: Fix 'SqlInjection' notices (#39219)
# Qual: Fix 'SqlInjection' notices

Batch of 25 files with changes to fix 'SqlInjection' Notices
2026-07-20 02:50:44 +02:00
Frédéric FRANCE
4d42bf735d
FIX: Translate French code comments to English in core module 2026-06-28 13:43:41 +02:00
Laurent Destailleur
6a3b9567be CI 2026-05-11 01:24:23 +02:00
MDW
1743565a50
Qual: Fix PHPStan notices (#37933)
* Qual: Fix phpstan notice with cast

* Qual: Fix initialiser (phpstan) and narrow some types

* Qual: Fix typing for object->type field (phpstan)

* Qual: Update preg_quote usage in step2.php

# Qual: Ignore false phpstan positive for preg_match

Add comment to ignore phpstan warning for preg_match argument

* Qual: Extend accepted types for arrayoptions (phpstan)

* Qual: Fix type hint typo

* Qual: Fix type for contact_id assignment

* Qual: Add menuonly as allowed reloadmode

* Qual: Add PHPStan ignore comments for argument.type

* Qual: Ignore unused parameter in constructors (PHPStan)

* Qual: Add type hint for $TMsg (PHPStan)

* Qual: Cast array values to match expected type (PHPStan)

* Qual: Cast $remise_percent_ligne to float (PHPStan)

* Qual: Add array specifier to GETPOST for correct type (PHPStan)

* Qual: Update sumSituation() argument types

* Qual: Cast value to string for printStdColumnContent (PHPStan)

* Qual: Ignore PHPStan notice for autoload function return value

* Qual: Fix type of argument to Menubase::recur (PHPStan)

* Qual: Fix return type hint (PHPStan)

* Qual: Add $dolibarr_main_db_type as default global

* Qual: Update Phan baseline (due to PHPStan fix)
2026-04-20 12:36:21 +02:00
Laurent Destailleur
c2db7a3220 Clean code 2026-04-14 18:40:54 +02:00
Laurent Destailleur
b3d355885a Clean code 2026-04-14 17:57:48 +02:00
MDW
f142240083
Qual: Fix phan notices (#37837)
* Qual: Ignore PhanUndeclaredProperty for specific lines

* Fix: Update payment mode reference in PDF generation

# Fix: Update payment mode reference in PDF generation

The payment mode reference in the PDF generation was incorrectly using `type_payment_code`, an unknown property in Salary.
It has been updated to use `type_code` as used elsewhere for the same purpose.

* Qual: Typing of several DDLUpdateField field_desc items made optional

# Qual: Typing of several DDLUpdateField field_desc items made optional

Not all fields are required for updateing the DB typing, and ExtraFields was not providing all of them.

* Qual: Update typing for phan notices

# Qual: Update typing for phan notices

Fix typing mismatches

* Qual: Fix extrafields typing in objectline_create.tpl.php

# Qual: Fix extrafields typing in objectline_create.tpl.php

- Update typing for phan

* Qual: Fix typing for Phan & re-use encrypted password when requested

# Qual: Fix typing for Phan & re-use encrypted password when requested

- Added a cast to string for the crypted password to hint phan that it returns the string version (not the array)
- Added a check to ensure the password is not already crypted before generating a new password.
- Updated the type hints for parameters `$changelater`, `$notrigger`, `$nosyncmember`, and `$passwordalreadycrypted` to include the range of possible values.
- Updated the return type hint for the `setPassword` method to include the range of possible error values.

* Qual: Fix file argument to showPreview() calls

# Qual: Fix file argument to showPreview() calls

Fix argument type mismatches by adjusting '$file' arguments in showPreview calls.

* Qual: Update login_c type to string

# Qual: Update login_c type to string

login_c is username from db.

* Qual: Update type hints in treeview.lib.php

# Qual: Update type hints in treeview.lib.php

Update type hints for static analysis.

* Qual: Add null check for objecttmp in selectForFormsList

# Qual: Add null check for objecttmp in selectForFormsList

Add null check for objecttmp before calling selectForFormsList to ensure static analysis

* Qual: Fix phan through null check on object argument

# Qual: Fix phan through null check on object argument

- Do null check to avoid null parameter (fix phan);
- Set more specific type for argument.

* Qual: Change type hint of $remise_percent parameter to float

# Qual: Change type hint of $remise_percent parameter to float

DB type is float, so correct arg type to fix phan notice.

* Qual: Ignore some phan notices

The descriptions for the linkedObjectsFullLoaded and oldcopy properties have been updated to avoid modification by code formatting tools

* Qual: Update phan baseline

* Qual: Cast remise_percent to float to match typing requirements

* Qual: Cast label to string to help static analysis

* Qual: Update date_cancel property type and assignment

To fix phan notices:

- The date_cancel property type was changed from 'int|string' to 'int|""' to match return type from jdate().
- Additionally, the assignment of date_cancel was updated to use dol_now() instead of $this->db->idate(dol_now()).

* Qual: Provide the expected user_id instead of the User object

Changed the user fetch logic from using `user_author` to `user_creation_id`

* Qual: Correct bool argument from 0 to false ($fill)

* Qual/Fix: Correct date converted to dol_print_date

* Qual: Fix argument type for addline()

* Qual: Update Phan baseline.txt
2026-04-13 12:50:23 +02:00
Laurent Destailleur
de04a5ffda Clean code - Bad consistency between addField and updateField 2026-03-23 12:58:05 +01:00
MDW
4e8b6dc21d
Qual: Translate french 'avec' comments to English (#37049)
# Qual: Translate french 'avec' comments to English
2026-02-01 18:09:39 +01:00
Frédéric FRANCE
8d459e469d
clean code (#36260)
* clean code

* clean code

* clean code

* clean code

* fix $val might not be defined

* fix phpstan errors reported

* fix phpstan errors reported

* fix phpstan errors reported

* fix phpstan errors reported

* fix phpstan errors reported

* fix phpstan errors reported

* ignore phpstan reported for later

* clean code

* clean code

* clean code

* clean

* test
2025-11-18 11:41:28 +01:00
ldestailleur
4a363478ae Clean code with rector 2025-09-18 16:26:38 +02:00
ldestailleur
4e89f046d1 Merge branch '21.0' of git@github.com:Dolibarr/dolibarr.git into 22.0 2025-09-01 16:47:39 +02:00
ldestailleur
bb0974add9 FIX Security when using feature Advanced Target of emailing (hidden in
v21, default in v22+). Possible SQL injection by users with permissions
to make mass emailing. Reported by Simon Perdrisat.
2025-09-01 16:38:01 +02:00
MDW
32bf8c5cd5
Qual: Fix phan notices (website) 2025-02-27 11:40:42 +01:00
MDW
97099b854f
Qual: Fix phan notices (install) 2025-02-05 01:43:41 +01:00
MDW
ba32606084
Fix return value for getListOfCollation() 2025-01-24 10:55:47 +01:00
Laurent Destailleur (aka Eldy)
f0ae6b999f Debug v21 2025-01-03 15:55:05 +01:00
MDW
ec2a1928ba
Qual: Update fields phpdoc to include fields that are defined/used in some cases
# Qual: Update fields phpdoc to include fields that are defined/used in some cases

comment, copytoclipboard, autofocusoncreated are documented and used in some cases for the
$fields definition
2024-12-05 02:36:50 +01:00
Frédéric FRANCE
1adc883b56
add baseline exclude for phpstan (#31632)
* add baseline exclude for phpstan

* update

* update

* update

* update

* update

* merge

* restore one filter

* delete old errors

* fix

* fix

* fix

* $moreforfilter can t be empty

* fix

* enable check

* refresh baseline

* add phpdoc

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* update phpstan baseline

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2024-11-04 23:53:20 +01:00
MDW
b91c99b18a
Qual: Fix phan/phpstan notices in class files (part 3) (#31578)
* fix phpstan in conf class (#31630)

* fix phpstan

* fix phan

* Fix merge

* Qual: Avoid notification with typing hint

* Qual: Fix notices link.class

* Qual: Fix notices link..socialneetworkmanager.class and DoliDb->DoliDB

* Qual: Fix notices for link..utils.class

* Qual: Fix notices for db classes

* Update translate.class.php

* Update translate.class.php

---------

Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com>
Co-authored-by: Laurent Destailleur <eldy@users.sourceforge.net>
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2024-10-29 22:44:47 +01:00
MDW
42bb4fbf3e
Qual: Enable & fix or ignore Invalid DimOffset (#31176)
* Qual: Enable & fix or ignore Invalid DimOffset

# Qual: Enable & fix or ignore Invalid DimOffset

The Invalid DimOffset notices occur when array keys are defined and
the index used is not amongst the known array keys.

This PR enables these notices and fixes array definitions when needed,
or ignores the notices locally if it's a false positive, or in the
baseline.txt when it does not seem to be a false positive so that
it can be fixed later

* Nullable object typing in function signature not ok for 7.0/8.4

Can't user '?User' as argument type for PHP7.0 which is required by PHP8.4.
Therefore, removing the typing specification in the function definition

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2024-09-29 21:52:31 +02:00
MDW
ca414de526
Qual: Fix $fields related notices with Phan (#30704)
* Qual: Typing hints/ignore directives for phan notices

* Update field typing
2024-08-21 13:23:35 +02:00
MDW
54880f92cd
Qual: Fix PhanTypeMismatchProperty and some other phan notices (#30542)
* Qual: Fix PhanTypeMismatchProperty and some other phan notices

* Qual: Phan fixes for BOM

* Phan - fix fields

* fixup! Qual: Phan fixes for BOM

* Fix phpstan double array keys for syslog

* Fix $fields phpdoc

* Fix phan typing issues with intermediate var and ??

* Fix phan typing issue with ?? operator

* Ignore htdocs/install/install.forced.php for git

* Qual: Revert to original code, ignore notice

When changing the method to avoid one notice type, another one
appears.  So simply ignoring this error.

* Qual: Revert to original code, ignore notice

When changing the method to avoid one notice type, another one
appears.  So simply ignoring this error.

* Update baseline

* Qual: Phan fixes for BOM

* fixup! Qual: Phan fixes for BOM

* Fix phpstan double array keys for syslog

* Qual: Revert to original code, ignore notice

When changing the method to avoid one notice type, another one
appears.  So simply ignoring this error.

* Ignore PhanTypeSuspiciousNonTraversableForeach to allow integration

* Fix typing hints (phpstan)

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2024-08-15 17:05:00 +02:00
MDW
d6948077b2
Qual: Fix spelling/update .pre-commit configuration (versions) (#30546)
* Qual: Update pre-commit configuration

* Qual: Update spelling

* Ignore use of deprecated constant
2024-08-07 01:20:43 +02:00
MDW
46eb5f83c2
Qual: Updates for phpstan notices (#30509)
* Fix int<0> typing to int<0,0> for phpstan

* Fix phpdoc for phpstan

* Fix phpdoc for phpstan

* Qual: Several phpstan notice fixes

* Fix phpdoc

* Qual: totalpaid is never null, remove null test

* improve phpdoc typing

* Also return null to statisfy phpstan

* Allow null value for $var

* object->Object to make it meaningful

* Type EvalMathStack properties

* Comment out unused private methods (phpstan)

* Changes for phpstan (return values, phpdoc, code)

* Change order of tests for phpstan

* phpdoc object to Object for correct typing

* Typing hing for phpstan

* UPdate test for phpstan

* Change phpdoc position for phpstan

* Update phpdoc for phpstan

This needs further improvement

* Change $op to $ope to fix phpstan

* Update sqlite3.class.php

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2024-08-01 12:59:45 +02:00
Laurent Destailleur
8963940c20 Fix phan 2024-04-28 17:38:39 +02:00
Laurent Destailleur
2aea004cba Fix phan 2024-04-28 17:36:33 +02:00
Laurent Destailleur
d1d68fdf8a Fix phan 2024-04-28 17:24:31 +02:00
Laurent Destailleur
6358f89c0d Fix phan warnings 2024-04-28 17:10:51 +02:00
Laurent Destailleur
2691603345 Doxygen 2024-04-27 18:04:27 +02:00
Laurent Destailleur
0d6675114e
Merge branch 'develop' into qual/db/typing 2024-03-21 13:19:51 +01:00
Laurent Destailleur
380c1092eb Fix warnings 2024-03-21 13:19:31 +01:00
Laurent Destailleur
f3e6b38d9d Fix warning 2024-03-21 13:16:59 +01:00
Laurent Destailleur
e97f0a7668
Merge branch 'develop' into qual/db/typing 2024-03-21 13:06:35 +01:00
Laurent Destailleur
58e719eb56 Fix sanitization 2024-03-21 13:03:30 +01:00
Laurent Destailleur
5fa2bfff2e
Merge branch 'develop' into qual/db/typing 2024-03-21 12:55:20 +01:00
Laurent Destailleur
61eefe5fa9
Merge branch 'develop' into fix/PhanTypeMismatchReturnNullable 2024-03-21 12:51:27 +01:00
Laurent Destailleur
04d8a20b63
Merge branch 'develop' into qual/db/typing 2024-03-21 12:46:25 +01:00
Laurent Destailleur
aa77573cd9 Sanitize DDL instructions 2024-03-21 12:45:58 +01:00
Laurent Destailleur
ce2959b022 Clean method DDLCreateTable (used by modulebuilder only) #28996 2024-03-21 12:10:09 +01:00
MDW
fc6af20479
Update typing for database functions 2024-03-21 00:00:00 +01:00
MDW
942239b5d6
Update PHPdoc to show nullable return 2024-03-20 23:54:32 +01:00
MDW
66c592717d
Fix PhanTypeMismatchBitwiseBinaryOperands by typing argument 2024-03-17 20:12:35 +01:00
MDW
9eed23c6d0
Fix return type by cast or typing update
# Fix return type by cast or typing update

Fix most PhanTypeMismatchReturn notifications.

The remaining ones are likely real bugs or need more Dolibarr
knowledge to fix them efficiently
2024-03-16 13:52:12 +01:00
MDW
0b19aa415c
Fix: Initialise array before assigning values (#28728)
* Qual: Enable PhanUndeclaredVariableDim

# Qual: Enable PhanUndeclaredVariableDim

The notifications are fixed in the code so the detection no longer
needs to be suppressed in the default flow

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Fix: initialise array before adding fields

* Qual: Add type hint to array to avoid phan notification

* Qual: Add type hint to array to avoid phan notification

* Qual: Enable PhanParamSpecial1 (all resolved)

* Qual: Ignore false PhanTypeArraySuspiciousNullable

* Qual: Improve typing to fix PhanTypeArraySuspicious

* Qual: Fix PhanTypeArraySuspicious by replacing null assignment with empty array

* Qual: Fix PhanTypeArraySuspicious by testing as instancof DebugBar

* Qual: Fix PhanTypeComparisonToArray with enhanced typing

* Qual: Fix PhanTypeComparisonToArray with enhanced typing

* Qual: Enable phan messages that no longer appear

* Qual: Exclude phan stubs from codesniffer ruleset
2024-03-09 16:32:02 +01:00
MDW
89004f7e03
Qual: Spelling htdocs/core (#27491)
Highlights:
- initialY in pdf_standard.modules.php was unused
  - remove (otherwise -> initially) (+same in other file)
2024-01-13 19:48:20 +01:00
Laurent Destailleur
8874ef8454 Debug v19 2023-12-23 18:47:38 +01:00
Frédéric FRANCE
61b79fda17 avoid phpstan error with phpdoc 2023-12-06 15:46:39 +01:00