Skip to content

{m365_defender,microsoft_defender_endpoint}.vulnerability: Handle empty response and 403 - #15749

Merged
kcreddy merged 9 commits into
elastic:mainfrom
kcreddy:mircrosoft-defender-vuln-fixes
Oct 30, 2025
Merged

{m365_defender,microsoft_defender_endpoint}.vulnerability: Handle empty response and 403#15749
kcreddy merged 9 commits into
elastic:mainfrom
kcreddy:mircrosoft-defender-vuln-fixes

Conversation

@kcreddy

@kcreddy kcreddy commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

Proposed commit message

{m365_defender,microsoft_defender_endpoint}.vulnerability: Handle empty response and 403 due to expired URLs.

We see cases where the API sends 200 with empty ("") response when 
fetching vulnerabilities using SAS URLs. Since this errored-URL is not 
removed from CEL work_list, it leads to following errors every interval:
"""
failed evaluation: failed eval: ERROR: <input>:2:43: file: EOF
 |   state.?work_list.orValue([]).size() > 0 ?
 | ..........................................^
"""

After a while when the signatures expire (controlled with `sas_valid_hours`), 
following error is noticed:
"""
<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:xxxxxx-xxxx-x-xxx--
Time:2025-10-20T02:07:09.6560520Z</Message><AuthenticationErrorDetail>Signature not valid in the specified key time frame: Key start [Mon, 20 Oct 2025 01:05:29 GMT] - Key expiry [Mon, 20 Oct 2025 02:05:29 GMT] - Current [Mon, 20 Oct 2025 02:07:09 GMT]</AuthenticationErrorDetail></Error>
"""

Handle both these cases in {m365_defender,microsoft_defender_endpoint}.vulnerability 
data stream by adding specific error.message asking users to increase "SAS Valid Hours"
config option. Add troubleshooting section inside the documentation indicating the same.


Also, bring the m365_defender.vulnerability in parity with 
microsoft_defender_endpoint.vulnerability data stream adding oauth endpoint options 
from #15667. 

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • I have verified that Kibana version constraints are current according to guidelines.
  • I have verified that any added dashboard complies with Kibana's Dashboard good practices

How to test this PR locally

  1. Add/Replace the following files inside packages/m365_defender/_dev/deploy/docker:
    download-vulnerability2.log.gz
    vulnerability-http-mock-config.yml

  2. Run system tests. eval "$(elastic-package stack shellinit)" && elastic-package test system --generate -v --data-streams=vulnerability

  3. This should produce error.message indicating users to increase SAS Valid Hours option.

Related issues

@kcreddy kcreddy changed the title {microsoft_defender_endpoint, m365_defender}.vulnerability: Handle empty response and 403 Oct 24, 2025
@kcreddy
kcreddy marked this pull request as ready for review October 24, 2025 13:53
@kcreddy
kcreddy requested a review from a team as a code owner October 24, 2025 13:53
@kcreddy kcreddy self-assigned this Oct 24, 2025
@kcreddy kcreddy added enhancement New feature or request Integration:microsoft_defender_endpoint Microsoft Defender for Endpoint Integration:m365_defender Microsoft Defender XDR bugfix Pull request that fixes a bug issue Team:Security-Service Integrations Security Service Integrations team [elastic/security-service-integrations] labels Oct 24, 2025
@elasticmachine

Copy link
Copy Markdown

Pinging @elastic/security-service-integrations (Team:Security-Service Integrations)

@kcreddy kcreddy added the documentation Improvements or additions to documentation. Applied to PRs that modify *.md files. label Oct 24, 2025
Comment thread packages/m365_defender/_dev/build/docs/README.md Outdated
"error": {
"code": string(resp.StatusCode),
"id": string(resp.Status),
"message": decoded_body.decode_error + ". Download URLs are likely expired.Try increasing the 'SAS Valid Hours' parameter to download more data.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"message": decoded_body.decode_error + ". Download URLs are likely expired.Try increasing the 'SAS Valid Hours' parameter to download more data.",
"message": decoded_body.decode_error + ": Download URLs are likely expired. Try increasing the 'SAS Valid Hours' parameter to download more data.",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment thread packages/microsoft_defender_endpoint/_dev/build/docs/README.md Outdated
"error": {
"code": string(resp.StatusCode),
"id": string(resp.Status),
"message": decoded_body.decode_error + ". Download URLs are likely expired.Try increasing the 'SAS Valid Hours' parameter to download more data.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"message": decoded_body.decode_error + ". Download URLs are likely expired.Try increasing the 'SAS Valid Hours' parameter to download more data.",
"message": decoded_body.decode_error + ": Download URLs are likely expired. Try increasing the 'SAS Valid Hours' parameter to download more data.",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in bf98c76

Comment thread packages/microsoft_defender_endpoint/docs/README.md Outdated
Comment thread packages/m365_defender/docs/README.md Outdated
@kcreddy
kcreddy requested a review from efd6 October 30, 2025 03:43
@elastic-vault-github-plugin-prod

elastic-vault-github-plugin-prod Bot commented Oct 30, 2025

Copy link
Copy Markdown
Contributor

🚀 Benchmarks report

To see the full report comment with /test benchmark fullreport

@efd6 efd6 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits

The alternative approach would be to check that the body is neither "" nor has a "<" prefix. Though I think that (from what I can make out from the description) will be more complex since the two things happen at different encoding levels in the response (as an aside, why do they use an XML error in a JSON API? or for that matter why explicitly gzip the body when the transport could transparently compress with exactly the same compression scheme ¯\_(ツ)_/¯.

All up, I think this is OK, mod the nits.

Comment thread packages/m365_defender/data_stream/vulnerability/agent/stream/cel.yml.hbs Outdated
@elasticmachine

Copy link
Copy Markdown

💚 Build Succeeded

History

cc @kcreddy

@kcreddy
kcreddy merged commit 77f1765 into elastic:main Oct 30, 2025
8 checks passed
@kcreddy
kcreddy deleted the mircrosoft-defender-vuln-fixes branch October 30, 2025 06:11
@elastic-vault-github-plugin-prod

Copy link
Copy Markdown
Contributor

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

@elastic-vault-github-plugin-prod

Copy link
Copy Markdown
Contributor

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

tehbooom pushed a commit to tehbooom/integrations that referenced this pull request Nov 19, 2025
…ty response and 403 (elastic#15749)

{m365_defender,microsoft_defender_endpoint}.vulnerability: Handle empty response and 403 due to expired URLs.

We see cases where the API sends 200 with empty ("") response when 
fetching vulnerabilities using SAS URLs. Since this errored-URL is not 
removed from CEL work_list, it leads to following errors every interval:
"""
failed evaluation: failed eval: ERROR: <input>:2:43: file: EOF
 |   state.?work_list.orValue([]).size() > 0 ?
 | ..........................................^
"""

After a while when the signatures expire (controlled with `sas_valid_hours`), 
following error is noticed:
"""
<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:xxxxxx-xxxx-x-xxx--
Time:2025-10-20T02:07:09.6560520Z</Message><AuthenticationErrorDetail>Signature not valid in the specified key time frame: Key start [Mon, 20 Oct 2025 01:05:29 GMT] - Key expiry [Mon, 20 Oct 2025 02:05:29 GMT] - Current [Mon, 20 Oct 2025 02:07:09 GMT]</AuthenticationErrorDetail></Error>
"""

Handle both these cases in {m365_defender,microsoft_defender_endpoint}.vulnerability 
data stream by adding specific error.message asking users to increase "SAS Valid Hours"
config option. Add troubleshooting section inside the documentation indicating the same.

Also, bring the m365_defender.vulnerability in parity with 
microsoft_defender_endpoint.vulnerability data stream adding oauth endpoint options 
from elastic#15667.
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 documentation Improvements or additions to documentation. Applied to PRs that modify *.md files. enhancement New feature or request Integration:m365_defender Microsoft Defender XDR Integration:microsoft_defender_endpoint Microsoft Defender for Endpoint Team:Security-Service Integrations Security Service Integrations team [elastic/security-service-integrations]

3 participants