Skip to content

[fortinet_fortigate] Fix NPE in VPN swap script for admin events. - #20399

Merged
haetamoudi merged 2 commits into
mainfrom
fix/0-in-the-painless-script-tag-script-345a587b-35747584
Jul 30, 2026
Merged

[fortinet_fortigate] Fix NPE in VPN swap script for admin events.#20399
haetamoudi merged 2 commits into
mainfrom
fix/0-in-the-painless-script-tag-script-345a587b-35747584

Conversation

@ie-ops

@ie-ops ie-ops commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Executive summary

A NullPointerException was thrown in the VPN swap script processor when processing administrative VPN events (e.g., SSL setting changes via ha_daemon) that carry no srcip or dstip fields. In those cases ctx.destination is never populated, so the assignment ctx.source = ctx.destination silently sets ctx.source to null; the subsequent ctx.source.user = tmp.user then throws. The fix inserts a null guard immediately after the swap assignment to initialize ctx.source to an empty map before any field access, preventing the NPE while still correctly preserving the user field from the original source context.

Proposed commit message

[fortinet_fortigate] Fix NPE in VPN swap script for admin events.

Root cause

The script processor (tag: script_345a587b) swaps ctx.source and ctx.destination for all VPN subtype events, but administrative VPN events (e.g. logid 0101041988, logdesc='SSL setting changed') carry no IP address fields, leaving ctx.destination null after earlier ECS-mapping processors. The script then assigns ctx.source = null and subsequently attempts ctx.source.user = tmp.user, throwing a NullPointerException because ctx.source is null.

Approach

In the Painless script (tag: script_345a587b) in event.yml, add a null-initialiser for ctx.source immediately after the swap assignment so that when ctx.destination is null (i.e., no IP address fields present for administrative VPN events like 'SSL setting changed'), the subsequent user-copy block does not throw a NullPointerException. Specifically, insert if (ctx.source == null) { ctx.source = [:]; } after ctx.source = ctx.destination;. Also add a new pipeline test fixture containing the sanitized administrative VPN event to exercise this branch. The on_failure handler already uses correct Mustache syntax so no change is needed there.

Implementation

  1. Step 1: Edit packages/fortinet_fortigate/data_stream/log/elasticsearch/ingest_pipeline/event.yml — in the script processor with tag script_345a587b, after the line ctx.source = ctx.destination;, insert if (ctx.source == null) { ctx.source = [:]; } so that the user-copy block operates on a valid (possibly empty) map rather than null.
  2. Step 2: Add the sanitized administrative VPN event to an existing or new test fixture file — append the sanitized syslog line <190>date=2026-06-26 time=10:54:36 devname="device-name-example-001" devid="SN000000000001" eventtime=1782482075598222761 tz="-0300" logid="0101041988" type="event" subtype="vpn" level="information" vd="root" logdesc="SSL setting changed" action="info" user="admin.access" ui="ha_daemon" msg="User changed SSL setting" to packages/fortinet_fortigate/data_stream/log/_dev/test/pipeline/test-fortinet-7-4.log.
  3. Step 3: Generate the matching expected output entry in packages/fortinet_fortigate/data_stream/log/_dev/test/pipeline/test-fortinet-7-4.log-expected.json by running elastic-package test pipeline --generate (or manually craft the expected JSON) to confirm no pipeline_error is set and source.user.name is 'admin.access'.
  4. Step 4: Update packages/fortinet_fortigate/changelog.yml — add a new version 1.36.6 entry with type: bugfix describing the fix.
  5. Step 5: Update the version field in packages/fortinet_fortigate/manifest.yml from 1.36.5 to 1.36.6 (patch bump).
  6. Step 6: Run elastic-package test pipeline to confirm the new test fixture passes and no existing fixtures regress.

Pipeline changes

  • Modify script processor (tag: script_345a587b) in event.yml: after ctx.source = ctx.destination;, add if (ctx.source == null) { ctx.source = [:]; } to prevent NPE when ctx.destination is null for administrative VPN events without IP fields.

Field / mapping changes

Sanitized error message

Processor 'script' with tag 'script_345a587b' in pipeline 'logs-fortinet_fortigate.log-event' failed with message '[on_failure_message]'

Sanitized log (event_sanitized excerpt)

<190>date=2026-06-26 time=10:54:36 devname="device-name-example-001" devid="SN000000000001" eventtime=1782482075598222761 tz="-0300" logid="0101041988" type="event" subtype="vpn" level="information" vd="root" logdesc="SSL setting changed" action="info" user="admin.access" ui="ha_daemon" msg="User changed SSL setting"

Reviewer concerns

• If an event has no srcip, no dstip, and no user field, the swap script will now leave ctx.source as an empty map {}. Depending on whether later processors clean up empty objects, this could result in a sparse source:{} field being indexed in edge-case documents — benign but worth verifying with additional log samples from similar administrative events.
• The changelog PR link is a placeholder (#1) and must be updated to the real PR URL before merging.

Self-review findings

Risk and classification

  • Plan risk level: low
  • Tags: pipeline, processors, ingest, test-fixture
  • Impact: medium

Links

  • Issue: (no issue number)
  • Issue title: fortinet_fortigate.log [PIPELINE_FIX]: Processor 'script' with tag 'script_345a587b' in pipeline 'logs-fortinet…
  • Pipeline case: 2deb93dffd8edb60

@ie-ops ie-ops added bugfix Pull request that fixes a bug issue Integration:fortinet_fortigate Fortinet FortiGate Firewall Logs source:integration_sentinel The PR was created via the Integration Sentinel pipeline Team:Integration-Experience Security Integrations Integration Experience [elastic/integration-experience] labels Jul 29, 2026
@haetamoudi
haetamoudi marked this pull request as ready for review July 29, 2026 16:32
@haetamoudi
haetamoudi requested a review from a team as a code owner July 29, 2026 16:32
@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

Pinging @elastic/integration-experience (Team:Integration-Experience)

@github-actions

Copy link
Copy Markdown
Contributor

✅ Elastic Docs Style Checker (Vale)

No issues found on modified lines!


The Vale linter checks documentation changes against the Elastic Docs style guide. To use Vale locally or report issues, refer to Elastic style guide for Vale.

@elastic-vault-github-plugin-prod

Copy link
Copy Markdown
Contributor

✅ All changelog entries have the correct PR link.

@vera-review-bot

Copy link
Copy Markdown

No issues across the latest commits f8a844b.

A new commit triggers another review — at most once every 15 minutes. I skip the PR while it's approved or has merge conflicts.

🤖 AI-Generated Review | Vera Review Bot | 📚 Knowledge base: integration-skills

⚠️ Automated review — verify suggestions before applying.

@elastic-vault-github-plugin-prod

Copy link
Copy Markdown
Contributor

🚀 Benchmarks report

To see the full report comment with /test benchmark fullreport

@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

💚 Build Succeeded

@mergify

mergify Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@haetamoudi
haetamoudi merged commit aaea6b3 into elastic:main Jul 30, 2026
9 checks passed
@elastic-vault-github-plugin-prod

Copy link
Copy Markdown
Contributor

Package fortinet_fortigate - 1.36.9 containing this change is available at https://epr.elastic.co/package/fortinet_fortigate/1.36.9/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Pull request that fixes a bug issue Integration:fortinet_fortigate Fortinet FortiGate Firewall Logs source:integration_sentinel The PR was created via the Integration Sentinel pipeline Team:Integration-Experience Security Integrations Integration Experience [elastic/integration-experience]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants