Skip to content

chore: Add Markdown Validation to OpenGraph Remediations and Kind Info Inputs - BED-8964 - #3092

Merged
LawsonWillard merged 24 commits into
mainfrom
BED-8964
Aug 7, 2026
Merged

chore: Add Markdown Validation to OpenGraph Remediations and Kind Info Inputs - BED-8964#3092
LawsonWillard merged 24 commits into
mainfrom
BED-8964

Conversation

@LawsonWillard

@LawsonWillard LawsonWillard commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

  • Adds to new library dependencies: Goldmark, for converting markdown into html, and bluemonday, for performing html sanitization.
  • Adds new unit tests to cover the new validation

Motivation and Context

Resolves: BED-8964

The OpenGraph Extension upload endpoint needs to validate and sanitize any markdown thats supplied as part of the extension: entity panels (kind info) and remediations.

How Has This Been Tested?

  • Adds new unit tests to ensure everything behaves as expected
  • Tested locally against a few of the extensions we have access to

Screenshots (optional):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

Summary by CodeRabbit

  • New Features

    • Added Markdown validation for graph schema extensions.
    • Supports safe Markdown, links, tables, and fenced code.
    • Validates node types, relationship types, and remediation descriptions.
  • Bug Fixes

    • Rejects unsafe HTML, scripts, malformed content, and invalid Markdown.
    • Prevents unsafe or invalid content from being uploaded or saved.
    • Handles equivalent HTML representations consistently during validation.

@LawsonWillard LawsonWillard self-assigned this Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 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: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 4f92a73a-6956-4b52-a6e2-942299f616bf

📥 Commits

Reviewing files that changed from the base of the PR and between 8ea7d6b and 686ef4d.

📒 Files selected for processing (1)
  • cmd/api/src/model/graphschema.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/api/src/model/graphschema.go

📝 Walkthrough

Walkthrough

The change adds Markdown extraction to kind information inputs. It validates kind and remediation Markdown during graph extension upserts by rendering, sanitizing, and normalizing HTML before persistence.

Changes

Graph extension Markdown validation

Layer / File(s) Summary
Markdown content contract
cmd/api/src/model/graphschema.go, cmd/api/src/model/graphschema_test.go
KindInfoInput.MarkdownContent extracts valid Markdown JSON content and rejects missing, unknown, or non-object content.
Markdown rendering and sanitization
cmd/api/src/services/opengraphschema/markdownsanitize.go, cmd/api/src/services/opengraphschema/markdownsanitize_test.go, go.mod
Goldmark renders Markdown with raw HTML preserved. Bluemonday sanitizes the output. Normalized differences cause validation errors.
Extension upsert validation
cmd/api/src/services/opengraphschema/extension.go, cmd/api/src/services/opengraphschema/opengraphschema.go, cmd/api/src/services/opengraphschema/extension_test.go
The service validates node kinds, relationship kinds, and remediation fields before upsert. Tests cover rejected scripts and accepted Markdown flows.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant UpsertOpenGraphExtension
  participant KindInfoInput
  participant markdownValidator
  participant Repository
  participant GraphKindRefresh
  UpsertOpenGraphExtension->>KindInfoInput: Extract Markdown content
  KindInfoInput-->>UpsertOpenGraphExtension: Markdown text or extraction error
  UpsertOpenGraphExtension->>markdownValidator: Validate kind and remediation Markdown
  markdownValidator-->>UpsertOpenGraphExtension: Validation result
  UpsertOpenGraphExtension->>Repository: Upsert validated extension
  Repository-->>UpsertOpenGraphExtension: Upsert result
  UpsertOpenGraphExtension->>GraphKindRefresh: Refresh graph kinds
Loading

Possibly related PRs

Suggested labels: api, enhancement, dependencies, go

Suggested reviewers: urangel

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: Markdown validation for OpenGraph remediations and Kind Info inputs.
Description check ✅ Passed The description covers the change, motivation, testing, ticket, change types, and checklist, with only minor wording and checklist cleanup needed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BED-8964

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

@coderabbitai coderabbitai Bot added api A pull request containing changes affecting the API code. dependencies Pull requests that update a dependency file enhancement New feature or request go Pull requests that update go code labels Aug 3, 2026

@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

Caution

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

⚠️ Outside diff range comments (1)
cmd/api/src/model/graphschema.go (1)

123-143: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Consolidate duplicate Markdown-content decoding logic.

validateKindInfoContent (Line 123) and the new MarkdownContent (Line 148) decode the same {"markdown":{"content":"..."}} JSON shape with the same DisallowUnknownFields and nil-check logic. Keep one implementation. Let validateKindInfoContent call MarkdownContent and discard the string, so future contract changes only need one update.

♻️ Proposed refactor to remove duplication
 func validateKindInfoContent(content json.RawMessage) error {
-	var (
-		contentWrapper struct {
-			Markdown struct {
-				Content *string `json:"content"`
-			} `json:"markdown"`
-		}
-		decoder = json.NewDecoder(strings.NewReader(string(content)))
-	)
-
-	decoder.DisallowUnknownFields()
-	if err := decoder.Decode(&contentWrapper); err != nil {
-		return ErrInvalidKindInfoContent
-	}
-
-	if contentWrapper.Markdown.Content == nil {
-		return ErrInvalidKindInfoContent
-	}
-
-	return nil
+	_, err := KindInfoInput{Content: content}.MarkdownContent()
+	return err
 }

Also applies to: 145-167

🤖 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 `@cmd/api/src/model/graphschema.go` around lines 123 - 143, Consolidate the
duplicate decoding logic by updating validateKindInfoContent to call
MarkdownContent and discard its returned string, propagating any validation
error. Remove the local decoder, wrapper, unknown-field handling, and nil check
from validateKindInfoContent while preserving its existing error contract and
keeping MarkdownContent as the single implementation.
🤖 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 `@cmd/api/src/services/opengraphschema/markdownsanitize.go`:
- Around line 1-2: Prepend the current header from LICENSE.header before the
package declaration in both
cmd/api/src/services/opengraphschema/markdownsanitize.go (lines 1-2) and
cmd/api/src/services/opengraphschema/markdownsanitize_test.go (lines 1-2); no
other changes are needed.
- Around line 30-41: Update newMarkdownValidator and its validation policy to
preserve safe GFM table alignment style attributes and fenced-code language
classes, either by allowing constrained values or configuring goldmark to omit
them; ensure validate accepts both cases. Add coverage for aligned tables and
language-tagged fenced code, and add the required LICENSE.header to
markdownsanitize.go and markdownsanitize_test.go.

---

Outside diff comments:
In `@cmd/api/src/model/graphschema.go`:
- Around line 123-143: Consolidate the duplicate decoding logic by updating
validateKindInfoContent to call MarkdownContent and discard its returned string,
propagating any validation error. Remove the local decoder, wrapper,
unknown-field handling, and nil check from validateKindInfoContent while
preserving its existing error contract and keeping MarkdownContent as the single
implementation.
🪄 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: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 8d66e6e9-dda9-44f3-a970-a40641a2920f

📥 Commits

Reviewing files that changed from the base of the PR and between 5088538 and b9f7a36.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (8)
  • cmd/api/src/model/graphschema.go
  • cmd/api/src/model/graphschema_test.go
  • cmd/api/src/services/opengraphschema/extension.go
  • cmd/api/src/services/opengraphschema/extension_test.go
  • cmd/api/src/services/opengraphschema/markdownsanitize.go
  • cmd/api/src/services/opengraphschema/markdownsanitize_test.go
  • cmd/api/src/services/opengraphschema/opengraphschema.go
  • go.mod

Comment thread cmd/api/src/services/opengraphschema/markdownsanitize.go
Comment thread cmd/api/src/services/opengraphschema/markdownsanitize.go

@ykaiboussiSO ykaiboussiSO 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.

Great work!
Image

@LawsonWillard
LawsonWillard merged commit 21047d4 into main Aug 7, 2026
13 checks passed
@LawsonWillard
LawsonWillard deleted the BED-8964 branch August 7, 2026 17:50
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api A pull request containing changes affecting the API code. dependencies Pull requests that update a dependency file enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants