Skip to content

feat(security): add SRI hash calculator - #652

Merged
TheVicky1 merged 1 commit into
TheVicky1:mainfrom
toyes3429:feat/sri-hash-calculator
Oct 23, 2026
Merged

TheVicky1 merged 1 commit into
TheVicky1:mainfrom
toyes3429:feat/sri-hash-calculator

Conversation

@toyes3429

Copy link
Copy Markdown
Contributor

🏛️ PACT Pull Request

1. Related Issue

Closes #433


2. Summary of Changes

  • Added generateSriHash(content, algorithm?) in src/lib/security/sri-hash-calculator.ts.
  • Supports string and Buffer content.
  • Uses SHA-384 by default and supports SHA-512.
  • Returns hashes in standard Subresource Integrity (SRI) format using Base64 encoding.
  • Added seven unit tests covering default behavior, SHA-512, buffers, empty content, and unsupported algorithms.

3. Motivation & Context

This utility provides a reusable way to generate Subresource Integrity hashes for scripts and stylesheets, helping support integrity verification for web resources.


4. Implementation Details

  • Uses Node.js's built-in crypto module.
  • Restricts the supported algorithms to sha384 and sha512.
  • Validates the content type and rejects unsupported algorithms with a TypeError.
  • Keeps the implementation independent of databases, APIs, and external packages.

5. Testing & Local Validation

  • npm run lint — ESLint passed with 0 errors
  • npx tsc --noEmit — TypeScript strict check passed with 0 errors
  • npm test — Full authoritative test matrix passed
  • npm run test:file -- sri-hash-calculator — Targeted test suite passed
  • node scratch/secret-scan.mjs — Zero secrets or sensitive credentials detected
  • npm run build — Production build succeeded without errors

Verification performed:

  • npm test -- sri-hash-calculator — 7 tests passed, 0 failed.
  • npm run typecheck — Reported as passed locally.

6. UI & Visual Changes

  • No UI changes.

7. Database & Security Impact

  • No database or authentication changes.
  • Adds a security-related utility for generating SRI hashes.

8. Documentation Impact

  • Documentation updates not required for this change.

9. Contributor Quality Checklist

  • 🌱 Micro-Contribution Fast-Path
  • My PR has a single, focused scope.
  • I have read and followed PACT's [Contributing Guide](https://github.com/TheVicky1/Pact_OS/blob/main/CONTRIBUTING.md).
  • I confirm that zero secrets, API keys, private tokens, or .env.local files are included.
  • My branch was created from the latest upstream/main with an appropriate prefix.
  • My commits follow the Conventional Commits format.
  • I have linked the target issue in Section 1.
  • I have reviewed my own diff for stray files or debugging artifacts.

@toyes3429
toyes3429 requested a review from TheVicky1 as a code owner October 21, 2026 17:59
@vercel

vercel Bot commented Oct 21, 2026

Copy link
Copy Markdown

@toyes3429 is attempting to deploy a commit to the Vicky's projects Team on Vercel.

A member of the Team first needs to authorize it.

@TheVicky1
TheVicky1 merged commit 1f4534d into TheVicky1:main Oct 23, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] Implement Subresource Integrity (SRI) Hash Calculator Helper

2 participants