Skip to content

feat(service-worker): Adds handling for security policy violation events - #63355

Closed
SkyZeroZx wants to merge 1 commit into
angular:mainfrom
SkyZeroZx:add-sw-securitypolicyviolation
Closed

SkyZeroZx wants to merge 1 commit into
angular:mainfrom
SkyZeroZx:add-sw-securitypolicyviolation

Conversation

@SkyZeroZx

Copy link
Copy Markdown
Contributor

feat(service-worker): Add securitypolicyviolation event handling and logging

Enables proper handling and logging of Content Security Policy (CSP) violations in Angular Service Workers, improving error detection and debugging capabilities for policy violations that may occur during service worker operations.

The change includes:

  • Added securitypolicyviolation event listener to the Driver class
  • Implemented onSecurityPolicyViolation method for handling CSP violation events
  • Added comprehensive unit tests to verify the new functionality
  • Updated test harness to support securitypolicyviolation event simulation
  • Enhanced error logging with violation event details for better debugging

Use Cases

  • CSP Compliance Monitoring: Detecting and logging when service worker operations violate Content Security Policy rules, ensuring compliance with security policies
  • Security Incident Detection: Identifying potential security threats or misconfigurations that trigger CSP violations in the service worker context
  • Debugging Support: Providing detailed logging information about CSP violations with the specific violation details and context for easier troubleshooting
  • Standards Compliance: Implementing the complete securitypolicyviolation event specification for comprehensive security event handling in service workers

Security Benefits:

  • Proactive detection of CSP violations in service worker context
  • Enhanced security monitoring capabilities for web applications
  • Improved compliance with security policies and regulations
  • Better incident response through detailed violation logging

This enhancement strengthens the security posture of Angular applications by providing visibility into CSP violations that occur within the service worker scope, enabling developers to quickly identify and resolve security policy issues.

@pullapprove
pullapprove Bot requested a review from crisbeto August 24, 2025 21:26
@angular-robot angular-robot Bot added detected: feature PR contains a feature commit area: service-worker Issues related to the @angular/service-worker package labels Aug 24, 2025
@ngbot ngbot Bot added this to the Backlog milestone Aug 24, 2025
Comment on lines +221 to +225
this.scope.addEventListener('securitypolicyviolation', (event) =>
// It seems that typescript has not registered the event as indicated in the documentation.
// See https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/securitypolicyviolation_event
this.onSecurityPolicyViolation(event as SecurityPolicyViolationEvent),
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like an issue on Ts's side. It's probably worth opening an issue on https://github.com/microsoft/TypeScript-DOM-lib-generator and reference it here.

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.

I just checked the Typescript issue and PRs, it's not listed, so I opened an issue.

@SkyZeroZx

Copy link
Copy Markdown
Contributor Author

Issue in Typescript : microsoft/TypeScript-DOM-lib-generator#2123

-Introduces support for capturing and logging security policy violations in the service worker.
- Improves debugging by surfacing violations instead of allowing silent failures.
@SkyZeroZx
SkyZeroZx force-pushed the add-sw-securitypolicyviolation branch from 248c5ca to 2f8dc1c Compare August 25, 2025 02:58
@JeanMeche

Copy link
Copy Markdown
Member

Per #63364, we won't be accepting feature PRs for the Service worker.

The message is also made public in our docs : https://angular.dev/ecosystem/service-workers

@JeanMeche JeanMeche closed this Aug 26, 2025
@SkyZeroZx
SkyZeroZx deleted the add-sw-securitypolicyviolation branch August 29, 2025 13:19
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: service-worker Issues related to the @angular/service-worker package detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants