Skip to content

Conversation

brian-olson
Copy link

Summary

This PR adds security documentation to help developers use Chart.js CDNs securely by implementing Subresource Integrity (SRI).

Changes

  • Added Security Considerations section to installation docs
  • Provided SRI examples for both CDNJS and jsDelivr CDNs
  • Included integrity hashes, crossorigin, and referrerpolicy attributes
  • Documented benefits of SRI for supply chain attack prevention
  • Added references to SRI hash generation tools

Benefits

Prevents CDN tampering attacks - Scripts are validated against cryptographic hashes
Supply chain security - Protects against compromised CDN infrastructure
Enterprise-ready - Follows security best practices for production deployments
Developer education - Teaches secure CDN usage patterns

Example Usage

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.5.0/chart.min.js" 
        integrity="sha512-n/G+dROKbKL3GVngGWmWfwK0yPctjZQM752diVYnXZtD/48agpUKLIn0xDQL9ydZ91x6BiOmTIFwWjjFi2kEFg==" 
        crossorigin="anonymous" 
        referrerpolicy="no-referrer">
</script>

This documentation improvement helps millions of Chart.js users implement security best practices when loading the library from CDNs.

Contributed by: OpenFlux Labs Security Team
References: MDN SRI Guide

- Add security section to installation documentation
- Provide SRI examples for both CDNJS and jsDelivr
- Include integrity hashes, crossorigin, and referrerpolicy attributes
- Explain benefits of SRI for supply chain attack prevention
- Add references to SRI hash generation tools

This helps developers secure their Chart.js CDN usage against tampering attacks.

Contributed by: OpenFlux Labs Security Team

When loading Chart.js from a CDN, it's recommended to use **Subresource Integrity (SRI)** to protect against tampered or malicious scripts. Here are secure examples:

### CDNJS with SRI
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this feature is not CDN specific and both CDN's are already described above I would keep this generic and just show a default config

- Protects against supply chain attacks
- Ensures script integrity in production environments

You can generate integrity hashes for any Chart.js version using tools like [SRI Hash Generator](https://www.srihash.org/) or find them on [cdnjs.com](https://cdnjs.com/libraries/Chart.js).
Copy link
Collaborator

Choose a reason for hiding this comment

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

The part about using external tools should be removed and only the part of keeping the hash of the CDN should be used.
We have no way of knowing if the linked tool is giving out false hashes.

@brian-olson brian-olson closed this by deleting the head repository Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants