Skip to content

feat(templates): require signatures for javascript templates - #7514

Merged
ehsandeep merged 2 commits into
devfrom
dwisiswant0/feat/templates/require-signatures-for-javascript-templates
Jul 3, 2026
Merged

feat(templates): require signatures for javascript templates#7514
ehsandeep merged 2 commits into
devfrom
dwisiswant0/feat/templates/require-signatures-for-javascript-templates

Conversation

@dwisiswant0

@dwisiswant0 dwisiswant0 commented Jun 30, 2026

Copy link
Copy Markdown
Member

Proposed changes

Unsigned javascript templates should not be
accepted into execution paths when template
signing is enforced.

Apply the signature check to javascript protocol
templates in both direct loading and workflows,
and report those skips separately from code
templates.

Closes #7513

Proof

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

A detailed high-level summary could not be generated for this review. Here is an overview derived from the analyzed file changes:

  • internal/runner/runner.go: ## AI-generated summary of changes
  • internal/tests/integration/code_test.go: ## AI-generated summary of changes
  • internal/tests/integration/javascript_krbroast_test.go: ## AI-generated summary of changes
  • internal/tests/integration/javascript_test.go: ## AI-generated summary of changes
  • internal/tests/integration/matcher-status_test.go: ## AI-generated summary of changes
  • internal/tests/integration/runner_test.go: ## AI-generated summary of changes
  • pkg/catalog/loader/loader.go: ## AI-generated summary of changes
  • pkg/catalog/loader/loader_test.go: ## AI-generated summary of changes
  • pkg/templates/compile_test.go: ## AI-generated summary of changes
  • pkg/templates/parser_stats.go: ## AI-generated summary of changes
  • pkg/templates/stats.go: ## AI-generated summary of changes
  • pkg/templates/templates_utils.go: ## AI-generated summary of changes
  • pkg/templates/workflows.go: ## AI-generated summary of changes
  • pkg/templates/signer/tmpl_signer.go: ## AI-generated summary of changes
  • pkg/templates/signer/tmpl_signer_test.go: ## AI-generated summary of changes

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9676ea2e-e8e1-4372-87e5-670d296eb121

📥 Commits

Reviewing files that changed from the base of the PR and between 1e2d7fb and e23c29c.

📒 Files selected for processing (15)
  • internal/runner/runner.go
  • internal/tests/integration/code_test.go
  • internal/tests/integration/javascript_krbroast_test.go
  • internal/tests/integration/javascript_test.go
  • internal/tests/integration/matcher-status_test.go
  • internal/tests/integration/runner_test.go
  • pkg/catalog/loader/loader.go
  • pkg/catalog/loader/loader_test.go
  • pkg/templates/compile_test.go
  • pkg/templates/parser_stats.go
  • pkg/templates/signer/tmpl_signer.go
  • pkg/templates/signer/tmpl_signer_test.go
  • pkg/templates/stats.go
  • pkg/templates/templates_utils.go
  • pkg/templates/workflows.go
👮 Files not reviewed due to content moderation or server errors (15)
  • internal/tests/integration/javascript_krbroast_test.go
  • pkg/templates/compile_test.go
  • internal/runner/runner.go
  • pkg/templates/signer/tmpl_signer_test.go
  • pkg/templates/signer/tmpl_signer.go
  • internal/tests/integration/runner_test.go
  • pkg/catalog/loader/loader.go
  • pkg/templates/stats.go
  • pkg/catalog/loader/loader_test.go
  • internal/tests/integration/javascript_test.go
  • pkg/templates/parser_stats.go
  • pkg/templates/templates_utils.go
  • internal/tests/integration/matcher-status_test.go
  • internal/tests/integration/code_test.go
  • pkg/templates/workflows.go

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The CRLF line-ending normalization in the signer and its test are unrelated to the JavaScript signing request. Move the signer normalization fix into a separate PR, or document it as an intentional companion change.
Docstring Coverage ⚠️ Warning Docstring coverage is 8.89% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: requiring signatures for JavaScript templates.
Linked Issues check ✅ Passed The PR implements signed JavaScript template gating, capability flags, and tests as requested in #7513.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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 dwisiswant0/feat/templates/require-signatures-for-javascript-templates

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/tests/integration/javascript_test.go`:
- Around line 497-501: The signing logic in runJavascriptTemplateAndGetResults
only covers jsTestcases, so templates passed in through filePath (like
javascriptNoAccess) can still hit the trust gate unsigned. Update the signing
step to include the current filePath being executed, or otherwise ensure every
JavaScript fixture used by this helper is signed before execution. Use the
runJavascriptTemplateAndGetResults flow and the templates.SignTemplate call as
the place to fix this.

In `@internal/tests/integration/runner_test.go`:
- Around line 203-205: The signing predicate for JavaScript templates is too
narrow and only matches protocol fixtures, so workflow JavaScript subtemplates
can bypass the signing prelude. Update needsSignedJavascriptTemplates to mirror
the workflow-aware logic used by needsSignedCodeTemplates by including the
workflow JavaScript fixture path pattern alongside the existing
protocol/javascript prefix. Keep the change localized to
needsSignedJavascriptTemplates so the integration runner applies signing
consistently across both template families.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 61a1dcc3-18f5-4502-aa21-a11779ec47b7

📥 Commits

Reviewing files that changed from the base of the PR and between ccbfb12 and 1c06427.

📒 Files selected for processing (30)
  • README.md
  • README_CN.md
  • README_ES.md
  • README_ID.md
  • README_JP.md
  • README_KR.md
  • README_PT-BR.md
  • README_TR.md
  • cmd/nuclei/main.go
  • cmd/tmc/main.go
  • internal/runner/runner.go
  • internal/tests/integration/code_test.go
  • internal/tests/integration/javascript_krbroast_test.go
  • internal/tests/integration/javascript_test.go
  • internal/tests/integration/matcher-status_test.go
  • internal/tests/integration/runner_test.go
  • lib/config.go
  • pkg/catalog/loader/loader.go
  • pkg/catalog/loader/loader_test.go
  • pkg/protocols/javascript/js_test.go
  • pkg/templates/capability.go
  • pkg/templates/compile.go
  • pkg/templates/compile_test.go
  • pkg/templates/parser_stats.go
  • pkg/templates/stats.go
  • pkg/templates/templates.go
  • pkg/templates/templates_test.go
  • pkg/templates/templates_utils.go
  • pkg/templates/workflows.go
  • pkg/types/types.go

Comment thread internal/tests/integration/javascript_test.go Outdated
Comment thread internal/tests/integration/runner_test.go Outdated

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/tests/functional/functional_test.go`:
- Around line 390-407: The functional test helper currently treats only a bare
-javascript as present, so explicit bool assignments like -javascript=false are
ignored and then overwritten by currentFunctionalArgs. Update hasFunctionalFlag
to recognize assignment forms for the javascript flag (for example, any arg
starting with the flag name plus "=") and keep currentFunctionalArgs from
appending -javascript when that flag is already explicitly set. Add a regression
test in the functional test suite to cover -javascript=false and verify it
remains unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dd55b74d-ddbe-47b2-b994-a4bfeee3dea7

📥 Commits

Reviewing files that changed from the base of the PR and between 1c06427 and be6e411.

📒 Files selected for processing (1)
  • internal/tests/functional/functional_test.go

Comment thread internal/tests/functional/functional_test.go Outdated

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/templates/signer/tmpl_signer.go (1)

97-106: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Imported file content isn't CRLF-normalized, leaving the cross-platform fix incomplete.

content is normalized via normalizeTemplateContentForSignature before signing/verifying, but bytes read from tmpl.GetFileImports() are appended raw (buff.Write(bin)). If an imported file has CRLF line endings (the exact Windows-checkout scenario this change targets), it will still produce different signatures depending on the checkout's line-ending state, defeating the purpose of the fix for templates with imports.

🔧 Normalize imported file bytes too
 	for _, file := range tmpl.GetFileImports() {
 		bin, err := os.ReadFile(file)
 		if err != nil {
 			return "", err
 		}
 		buff.WriteRune('\n')
-		buff.Write(bin)
+		buff.Write(normalizeTemplateContentForSignature(bin))
 	}

(apply the analogous change in Verify as well)

Also applies to: 149-158

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/templates/signer/tmpl_signer.go` around lines 97 - 106, The signing and
verification paths in Sign and Verify still append imported file bytes from
tmpl.GetFileImports() without normalization, so the CRLF fix is incomplete for
templates with imports. Update both functions to run the bytes read from
os.ReadFile through normalizeTemplateContentForSignature before writing them
into the buffer, using the existing buff setup as the reference point, so
imported files are treated the same as the main content.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pkg/templates/signer/tmpl_signer.go`:
- Around line 97-106: The signing and verification paths in Sign and Verify
still append imported file bytes from tmpl.GetFileImports() without
normalization, so the CRLF fix is incomplete for templates with imports. Update
both functions to run the bytes read from os.ReadFile through
normalizeTemplateContentForSignature before writing them into the buffer, using
the existing buff setup as the reference point, so imported files are treated
the same as the main content.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 17a8ace2-0c7c-4dfa-801f-95f57634680f

📥 Commits

Reviewing files that changed from the base of the PR and between be6e411 and 1e2d7fb.

📒 Files selected for processing (2)
  • pkg/templates/signer/tmpl_signer.go
  • pkg/templates/signer/tmpl_signer_test.go

@dwisiswant0
dwisiswant0 marked this pull request as draft July 1, 2026 11:29
Unsigned javascript templates should not be
accepted into execution paths when template
signing is enforced.

Apply the signature check to javascript protocol
templates in both direct loading and workflows,
and report those skips separately from code
templates.

Signed-off-by: Dwi Siswanto <git@dw1.io>
@dwisiswant0
dwisiswant0 force-pushed the dwisiswant0/feat/templates/require-signatures-for-javascript-templates branch from 1e2d7fb to f8c7f7b Compare July 2, 2026 07:48
The verifier already canonicalizes CRLF to LF
before checking the digest, but the signer still
hashed the raw file content. Templates signed from
a CRLF checkout could fail verification later,
which showed up on Windows after javascript
fixtures started being signed in the integration
harness.

Use the same canonical content for signing and
verification, and add a CRLF sign-and-verify
regression.

Signed-off-by: Dwi Siswanto <git@dw1.io>
@dwisiswant0
dwisiswant0 marked this pull request as ready for review July 2, 2026 12:14
@dwisiswant0
dwisiswant0 requested a review from ehsandeep July 2, 2026 12:14
@ehsandeep
ehsandeep merged commit fac0b71 into dev Jul 3, 2026
29 of 30 checks passed
@ehsandeep
ehsandeep deleted the dwisiswant0/feat/templates/require-signatures-for-javascript-templates branch July 3, 2026 00:20
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.

extend template signing to the JavaScript protocol

2 participants