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

[Security Solution] Rule filters: strict schema #147438

Open
Tracked by #138606
banderror opened this issue Dec 13, 2022 · 1 comment
Open
Tracked by #138606

[Security Solution] Rule filters: strict schema #147438

banderror opened this issue Dec 13, 2022 · 1 comment
Labels
Feature:Rule Management Security Solution Detection Rule Management area Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. technical debt Improvement of the software architecture and operational architecture

Comments

@banderror
Copy link
Contributor

banderror commented Dec 13, 2022

Epic: #138606
Related to: #147441

Summary

Currently, query filters stored in rules of selected types are typed as an array of t.unknown values which allows a user to store anything in there via the API.

/**
* TODO: Right now the filters is an "unknown", when it could more than likely
* become the actual ESFilter as a type.
*/
export type RuleFilterArray = t.TypeOf<typeof RuleFilterArray>; // Filters are not easily type-able yet
export const RuleFilterArray = t.array(t.unknown); // Filters are not easily type-able yet

For example, for the Custom Query rules, filters are defined here:

If a user stores an invalid value instead of a valid instance of a filter model, it might break both the UI (e.g. rule Creation and Details pages) and the BE logic (rule executors).

Let's implement a strict io-ts schema for filters and validate them on-write.

To do

Let's do the following:

  • Figure out what is the model of the filters we use. Find existing TypeScript types for it, find existing validation functions.
  • Implement a strict io-ts schema for a filter and replace t.unknown with it in RuleFilterArray.
  • Consider handling (potentially invalid) values already stored in filters. We could try to make sure whatever filters we return from the API are valid objects. Options could be: do an on-read validation or normalization, implement a rule migration,...
@banderror banderror added technical debt Improvement of the software architecture and operational architecture Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Feature:Rule Management Security Solution Detection Rule Management area Team:Detection Rule Management Security Detection Rule Management Team labels Dec 13, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Rule Management Security Solution Detection Rule Management area Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. technical debt Improvement of the software architecture and operational architecture
Projects
None yet
Development

No branches or pull requests

2 participants