Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate rule type guidance as markdown. #4292

Merged
merged 1 commit into from
Aug 28, 2024
Merged

Validate rule type guidance as markdown. #4292

merged 1 commit into from
Aug 28, 2024

Conversation

blkt
Copy link
Contributor

@blkt blkt commented Aug 27, 2024

Summary

We're currently treating guidance as a plain string, storing it unmodified.

This change introduces some controls ensuring that guidance is valid markdown before storing it in the database. Since any valid UTF-8 string is valid markdown, the check is a bit redundant at the moment and ensures that it is parseable and renderable as HTML.

Additionally, we limit its size to 10kB, which is far more than enough given the current rule types have a guidance field shorter than 1kB.

Fixes #4286

Change Type

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Manual tests.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@blkt blkt self-assigned this Aug 27, 2024
Copy link

Minder Vulnerability Report ✅

Minder analyzed this PR and found it does not add any new vulnerable dependencies.

Vulnerability scan of c201e626:

  • 🐞 vulnerable packages: 0
  • 🛠 fixes available for: 0

@blkt blkt changed the title Ensure rule type guidance is valid markdown. Validate rule type guidance as markdown. Aug 27, 2024
@coveralls
Copy link

coveralls commented Aug 27, 2024

Coverage Status

Changes unknown
when pulling 14de03a on issue-4286
into ** on main**.

rdimitrov
rdimitrov previously approved these changes Aug 27, 2024
Copy link
Contributor

@JAORMX JAORMX left a comment

Choose a reason for hiding this comment

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

Should this also cover `UpdateRuleType?

),
)
if err := md.Convert([]byte(crt.RuleType.Guidance), &bytes.Buffer{}); err != nil {
return nil, status.Errorf(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a user-facing issue? We have a UserVisibleError wrapper that allows for this.

return nil, status.Errorf(
codes.InvalidArgument,
"invalid rule type definition: guidance too long",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a user-facing issue? We have a UserVisibleError wrapper that allows for this.

We're currently treating `guidance` as a plain string, storing it
unmodified.

This change introduces some controls ensuring that guidance is valid
markdown before storing it in the database. Since any valid UTF-8
string is valid markdown, the check is a bit redundant at the moment
and ensures that it is parseable and renderable as HTML.

Additionally, we limit its size to 10kB, which is far more than enough
given the current rule types have a `guidance` field shorter than 1kB.

Fixes #4286
@blkt
Copy link
Contributor Author

blkt commented Aug 28, 2024

Thanks for catching that @JAORMX

@blkt blkt merged commit 805b55a into main Aug 28, 2024
21 checks passed
@blkt blkt deleted the issue-4286 branch August 28, 2024 09:29
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.

Validate rule type guidance as markdown
4 participants