Skip to content

[MM-68690] Null check on missing headers when loading resources#3812

Merged
devinbinnie merged 1 commit into
masterfrom
MM-68690
May 8, 2026
Merged

[MM-68690] Null check on missing headers when loading resources#3812
devinbinnie merged 1 commit into
masterfrom
MM-68690

Conversation

@devinbinnie
Copy link
Copy Markdown
Member

@devinbinnie devinbinnie commented May 7, 2026

Summary

Certain network responses can be missing headers that the downloads manager assumed were always present, leading to an unhandled error.

This PR adds defensive null checks when reading response headers in the downloads handler.

Ticket Link

https://mattermost.atlassian.net/browse/MM-68690

Release Note

Improved robustness of the downloads handler when handling unexpected network responses.

Change Impact: 🟢 Low

Regression Risk: Minimal. The changes are purely defensive—adding optional chaining operators (?.) and optional method calls (?.join?.()) to guard against missing content-disposition headers in network responses. The logic flow remains unchanged when headers are present, and the new null checks only prevent crashes in edge cases. The fix is scoped to a single, isolated method (webRequestOnHeadersReceivedHandler) within the downloads feature. No shared utilities, base classes, or widely-imported modules are affected.

QA Recommendation: Minimal manual QA required. The fix addresses a specific edge case (missing headers) that is already covered by an added unit test. Basic smoke testing of the downloads feature is recommended to verify that normal download flows (with complete headers) remain unaffected, but comprehensive testing can rely on the unit test coverage.

Generated by CodeRabbitAI

@devinbinnie devinbinnie added this to the v6.2.0 milestone May 7, 2026
@devinbinnie devinbinnie added the 3: Security Review Review requested from Security Team label May 7, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7ac6c6a0-08ac-46e3-b075-0b502ec6581f

📥 Commits

Reviewing files that changed from the base of the PR and between 7595a62 and e994cb2.

📒 Files selected for processing (2)
  • src/main/downloadsManager.test.js
  • src/main/downloadsManager.ts

📝 Walkthrough

Walkthrough

This PR adds defensive programming to the downloads manager's header handling. The webRequestOnHeadersReceivedHandler method now safely handles missing or malformed content-disposition headers using optional chaining, preventing null-reference crashes. A new test case verifies this behavior.

Changes

Content-Disposition Header Robustness

Layer / File(s) Summary
Implementation Fix
src/main/downloadsManager.ts
Optional chaining applied to headers['content-disposition'].join(';') to safely handle cases where the header is missing or not array-like.
Test Validation
src/main/downloadsManager.test.js
New test case (MM-68690) ensures webRequestOnHeadersReceivedHandler does not throw when content-disposition is absent and verifies callback receives an empty object.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately reflects the main change: adding null checks for missing headers in the downloads manager to handle edge cases.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch MM-68690

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the E2E/Run Run Desktop E2E Tests label May 7, 2026
@devinbinnie devinbinnie requested a review from edgarbellot May 7, 2026 16:13
@mm-cloud-bot
Copy link
Copy Markdown

❌ E2E Test Setup Failed

Failed to create E2E test instances: failed to create installation: failed with status code 409

@devinbinnie devinbinnie added the CherryPick/Approved Meant for the quality or patch release tracked in the milestone label May 7, 2026
Copy link
Copy Markdown

@edgarbellot edgarbellot left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@edgarbellot edgarbellot removed the 3: Security Review Review requested from Security Team label May 8, 2026
@devinbinnie devinbinnie merged commit 9538d4d into master May 8, 2026
37 checks passed
@devinbinnie devinbinnie deleted the MM-68690 branch May 8, 2026 12:55
@mattermost-build
Copy link
Copy Markdown
Contributor

Cherry pick is scheduled.

@devinbinnie devinbinnie added the 4: Reviews Complete All reviewers have approved the pull request label May 8, 2026
@mattermost-build mattermost-build added CherryPick/Done Successfully cherry-picked to the quality or patch release tracked in the milestone and removed CherryPick/Approved Meant for the quality or patch release tracked in the milestone labels May 8, 2026
@devinbinnie
Copy link
Copy Markdown
Member Author

/cherry-pick release-5.13

@mattermost-build
Copy link
Copy Markdown
Contributor

Cherry pick is scheduled.

devinbinnie added a commit that referenced this pull request May 8, 2026
… (#3814)

(cherry picked from commit 9538d4d)

Co-authored-by: Devin Binnie <52460000+devinbinnie@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4: Reviews Complete All reviewers have approved the pull request CherryPick/Done Successfully cherry-picked to the quality or patch release tracked in the milestone E2E/Run Run Desktop E2E Tests release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants