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

Suricata Rules can only be 1 Line #562

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion html/js/external/prism-custom-v1.29.0.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions server/detectionhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ func (h *DetectionHandler) createDetection(w http.ResponseWriter, r *http.Reques
return
}

_, err = engine.ValidateRule(detect.Content)
if err != nil {
web.Respond(w, r, http.StatusBadRequest, fmt.Errorf("invalid rule: %w", err))
return
}

err = engine.ExtractDetails(detect)
if err != nil {
if err.Error() == "rule does not contain a public Id" {
Expand Down Expand Up @@ -277,6 +283,12 @@ func (h *DetectionHandler) updateDetection(w http.ResponseWriter, r *http.Reques
return
}

_, err = engine.ValidateRule(detect.Content)
if err != nil {
web.Respond(w, r, http.StatusBadRequest, fmt.Errorf("invalid rule: %w", err))
return
}

err = h.PrepareForSave(ctx, detect, engine)
if err != nil {
if err.Error() == "Object not found" {
Expand Down
9 changes: 9 additions & 0 deletions server/modules/suricata/suricata.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,15 @@ func readFingerprint(path string) (fingerprint *string, ok bool, err error) {
}

func (e *SuricataEngine) ValidateRule(rule string) (string, error) {
lines := strings.Split(rule, "\n")
nonEmpty := lo.Filter(lines, func(line string, _ int) bool {
return strings.TrimSpace(line) != ""
})

if len(nonEmpty) != 1 {
return "", fmt.Errorf("suricata rules must be a single line")
}

parsed, err := ParseSuricataRule(rule)
if err != nil {
return rule, err
Expand Down
Loading