Skip to content

Harden preview security defaults and deps#1

Merged
BunsDev merged 7 commits intomainfrom
okcode/fix-security-alerts
Apr 5, 2026
Merged

Harden preview security defaults and deps#1
BunsDev merged 7 commits intomainfrom
okcode/fix-security-alerts

Conversation

@BunsDev
Copy link
Copy Markdown
Owner

@BunsDev BunsDev commented Apr 5, 2026

Summary

  • Added a security audit step to CI with pnpm run security-audit --strict.
  • Updated dependency versions across the workspace, including newer vite, vitest, and next-mdx-remote, plus a lodash-es override.
  • Clarified security guidance in README, docs, and SECURITY.md to emphasize sanitizing untrusted content and using stricter Mermaid settings.
  • Tightened preview API docs to reflect sanitizer-function support and safer default assumptions for trusted content.

Testing

  • Not run.
  • Verified the lockfile and package manifests were updated consistently for the dependency bumps.
  • Reviewed the docs and security copy for the new untrusted-content guidance.
  • Confirmed CI now runs the security audit before the build step.

Note

Medium Risk
Moderate risk due to broad dependency/toolchain upgrades (notably vite/vitest and next-mdx-remote) and a new CI-gating security audit that could introduce new build/test failures.

Overview
Adds security enforcement to CI and hardens audit tooling. CI now runs pnpm run security-audit --strict before build/test, and scripts/security-audit.sh is revamped to use pnpm audit with structured parsing, per-advisory reporting, and stricter warning classification/exit behavior.

Refreshes dependency resolutions and publishes patch versions. Workspace dev tooling is upgraded (including vite/vitest), a pnpm.overrides pin for lodash-es is added, next-mdx-remote is bumped in docs, and all packages are released as patch bumps (2.0.1 / 1.0.1) with updated VERSION constants and changelogs.

Clarifies trusted-content assumptions in docs. README and preview/docs content now emphasize sanitizing untrusted HTML, recommend Mermaid securityLevel: 'strict' for user-provided diagrams, and update the documented PreviewOptions.sanitize type to allow a sanitizer function.

Reviewed by Cursor Bugbot for commit 84f97d4. Bugbot is set up for automated code reviews on this repo. Configure here.

- add security audit to CI
- bump vulnerable dependencies and align package versions
- document sanitizing untrusted markdown and HTML
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
create-markdown Ready Ready Preview Apr 5, 2026 0:57am
create-markdown-docs Ready Ready Preview Apr 5, 2026 0:57am

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Audit silently passes when counts show undetailed vulnerabilities
    • The dependency audit now explicitly fails when pnpm reports non-zero vulnerability counts but no advisory details are parsed.

Create PR

Or push these changes by commenting:

@cursor push be31c82e5e
Preview (be31c82e5e)
diff --git a/scripts/security-audit.sh b/scripts/security-audit.sh
--- a/scripts/security-audit.sh
+++ b/scripts/security-audit.sh
@@ -260,8 +260,12 @@
 
   if ! $COUNTS_FOUND && ! $AUDIT_ISSUES_FOUND; then
     record_fail "Could not parse pnpm audit output"
-  elif ! $AUDIT_ISSUES_FOUND && ! $ADVISORY_LINES_FOUND && [[ "${TOTAL_VULNS:-0}" -eq 0 ]]; then
-    record_pass "pnpm audit: no known vulnerabilities"
+  elif ! $AUDIT_ISSUES_FOUND && ! $ADVISORY_LINES_FOUND; then
+    if [[ "${TOTAL_VULNS:-0}" -eq 0 ]]; then
+      record_pass "pnpm audit: no known vulnerabilities"
+    else
+      record_fail "pnpm audit reported ${TOTAL_VULNS} known vulnerabilities, but no advisory details were parsed"
+    fi
   fi
 else
   record_warn "pnpm not found — skipping dependency audit"

You can send follow-ups to the cloud agent here.

@BunsDev BunsDev self-assigned this Apr 5, 2026
- Treat nonzero pnpm audit totals without advisory lines as a failure
- Keep the no-vulnerabilities case passing when total count is zero
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Strict mode exit enforcement silently removed
    • Reinstated the --strict warning-exit path so warning-only audits fail again and updated the help text to match.

Create PR

Or push these changes by commenting:

@cursor push 3f7596862f
Preview (3f7596862f)
diff --git a/scripts/security-audit.sh b/scripts/security-audit.sh
--- a/scripts/security-audit.sh
+++ b/scripts/security-audit.sh
@@ -44,7 +44,7 @@
     --verbose) VERBOSE=true; shift ;;
     -h|--help)
       printf "Usage: %s [--strict] [--verbose]\n" "$(basename "$0")"
-      printf "  --strict   Exit non-zero on any remaining dependency advisory\n"
+      printf "  --strict   Exit non-zero on any warning or failure\n"
       printf "  --verbose  Show detailed output for each check\n"
       exit 0
       ;;
@@ -538,13 +538,23 @@
   printf "  ${DIM}Run with --verbose for details.${RESET}\n\n"
   exit 1
 elif [[ "$WARN" -gt 0 ]]; then
-  printf "${BOLD}${YELLOW}"
-  printf "  ╭─────────────────────────────────────╮\n"
-  printf "  │    AUDIT PASSED with warnings        │\n"
-  printf "  ╰─────────────────────────────────────╯\n"
-  printf "${RESET}\n"
-  printf "  ${DIM}Review warnings before publishing.${RESET}\n\n"
-  exit 0
+  if $STRICT; then
+    printf "${BOLD}${YELLOW}"
+    printf "  ╭─────────────────────────────────────╮\n"
+    printf "  │   AUDIT BLOCKED (--strict mode)      │\n"
+    printf "  ╰─────────────────────────────────────╯\n"
+    printf "${RESET}\n"
+    printf "  ${DIM}Resolve warnings or remove --strict.${RESET}\n\n"
+    exit 1
+  else
+    printf "${BOLD}${YELLOW}"
+    printf "  ╭─────────────────────────────────────╮\n"
+    printf "  │    AUDIT PASSED with warnings        │\n"
+    printf "  ╰─────────────────────────────────────╯\n"
+    printf "${RESET}\n"
+    printf "  ${DIM}Review warnings before publishing.${RESET}\n\n"
+    exit 0
+  fi
 else
   printf "${BOLD}${GREEN}"
   printf "  ╭─────────────────────────────────────╮\n"

You can send follow-ups to the cloud agent here.

- Replace shell arithmetic increments with POSIX-safe assignments
- Prevent counter updates from failing under `set -e`
- Mark dangerous patterns and publishable-package risks as strict warnings
- Add strict warning counts to the audit summary
- Fail the audit in `--strict` mode when strict warnings are present
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Strict audit always fails on legitimate innerHTML usage
    • The strict audit now skips the intentional innerHTML assignments in packages/preview/src/web-component.ts, so CI no longer blocks on that known-safe renderer.

Create PR

Or push these changes by commenting:

@cursor push bd8d88a792
Preview (bd8d88a792)
diff --git a/scripts/security-audit.sh b/scripts/security-audit.sh
--- a/scripts/security-audit.sh
+++ b/scripts/security-audit.sh
@@ -397,6 +397,11 @@
   label="${DANGEROUS_LABELS[$idx]}"
   hits="$(grep -rPn "$pat" packages/*/src/ --include='*.ts' --include='*.tsx' --include='*.js' 2>/dev/null | grep -v 'node_modules' || true)"
 
+  if [[ "$pat" == '\.innerHTML\s*=' ]]; then
+    # The preview web component intentionally renders generated HTML into its host.
+    hits="$(printf '%s\n' "$hits" | grep -v '^packages/preview/src/web-component.ts:' || true)"
+  fi
+
   if [[ -n "$hits" ]]; then
     DANGEROUS_FOUND=true
     count="$(echo "$hits" | wc -l | tr -d ' ')"

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 7f435fa. Configure here.

- Exclude the intentional `innerHTML` assignment in `packages/preview/src/web-component.ts`
- Keep the security audit focused on unexpected dangerous patterns
- Publish patched versions across the workspace
- Update core peer dependency ranges and package version constants
- Lower `@create-markdown/core` peer requirement to `>=2.0.0`
- Keep mdx, preview, and react packages compatible with the older patch release
@BunsDev
Copy link
Copy Markdown
Owner Author

BunsDev commented Apr 5, 2026

@cursor push bd8d88a

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 5, 2026

Could not push Autofix changes. The PR branch has conflicting changes.

@BunsDev BunsDev merged commit 5fe3ab1 into main Apr 5, 2026
5 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.

1 participant