Skip to content

Bootstrap sync - dry run#20

Open
f2cmb wants to merge 4 commits into
mainfrom
sync/boostrap
Open

Bootstrap sync - dry run#20
f2cmb wants to merge 4 commits into
mainfrom
sync/boostrap

Conversation

@f2cmb

@f2cmb f2cmb commented Jun 11, 2026

Copy link
Copy Markdown
Contributor
  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

Trigger an LDAP → GLPI inventory sync from a SyncFilter (Computer itemtype),in dry-run (preview create/update counts, no write) or execute (inject via Glpi\Inventory\Inventory).

Adds ajax/syncexecute.php (rights + auth checks), LdapSyncExecutor, previewSyncFilter() and the execution UI. Rebased on main (PR #18).

f2cmb added 4 commits June 11, 2026 16:18
- ajax/syncexecute.php: import Safe\session_write_close and narrow POST id with is_numeric before int cast (avoids cast.int on mixed)
- src/Inventory/LdapSyncExecutor.php, src/SyncFilter.php: rector FlipTypeControlToUseExclusiveTypeRector + NewlineAfterStatementRector
- front/authldapsyncfilter.form.php: drop always-true null guard and ignore argument.type on add() (phpstan drift from GLPI core bump)
Critical:
- SyncFilter: use AuthLDAP field 'deref_option' (not 'deref', which never
  exists and silently fell back to 0); robust is_numeric cast in both spots.

Major:
- LdapSyncExecutor: stop silently returning empty results — log + skipped++
  when a SyncFilter has no linked AuthLDAP (executeSingleFilter) and log the
  null-AuthLDAP/null-builder preview paths. Prevents a false 'disappeared'
  signal for future lifecycle handling.
- LdapSyncExecutor::replacePlaceholders: substitute LDAP values inside the PHP
  structure (string leaves only) instead of into a re-serialized JSON string
  with a hand-rolled addcslashes escaper. Closes JSON key-injection and
  control-character corruption from attacker-controlled LDAP values.
- AuthLdapSyncFilter::prepareInputForAdd: whitelist the two relation foreign
  keys (array_intersect_key) to prevent mass assignment.
- SyncFilter::showBuilderMappingTab: render alerts via a Twig partial using
  core alerts_macros and pass Monaco CSS as a template var instead of echoing
  raw HTML from a class method.
- LdapSyncExecutor: trim verbose narrating class PHPDoc.

Tests:
- previewSyncFilter without linked AuthLDAP (result + log);
- replacePlaceholders cannot inject inventory keys / preserves control chars;
- prepareInputForAdd strips unknown keys.

Note: Hooks::CSRF_COMPLIANT intentionally NOT added — deprecated since GLPI
11.0 (CSRF enforced by CheckCsrfListener); declaring it would fail phpstan.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle sync

1 participant