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

Prevent input name collision with db name for refs (#6056) #6080

Merged
merged 11 commits into from
Feb 27, 2024

Conversation

labo-flg
Copy link
Member

@labo-flg labo-flg commented Feb 22, 2024

Several refs attributes have the same input name as their db name, resulting in bugs during stream event publishing.

If the attribute is multiple, the event published in stream contains null in patch.
If it's a single value, the stream event won't be sent and an error will be thrown (store update event error)

Proposed changes

  • on schema registration, check the names collisions and throw an error
  • fix all collisions found by prefixing the name
  • rename API keys that require changes (--> only MalwareAnalysisAddInput.sample to rename MalwareAnalysisAddInput.analysisSample

Related issues

Checklist

  • I consider the submitted work as finished
  • I tested the code for its functionality
  • I wrote test cases for the relevant uses case
  • I added/update the relevant documentation (either on github or on notion)
  • Where necessary I refactored code to improve the overall quality

Further comments

e2e tests would be added in #6073 to cover network traffic creation + ref, I won't add it here (or improve on it here once merge and rebase)

To test this PR, test the following:

  • open the raw stream at http://localhost:3000/stream
  • Create an observable > network traffic, with a random dst port
  • Open it, go to knowledge, and add a nested object
  • check single ref
  • check multiple ref
    • create 2 other network traffic using just some random DST port values
    • select the inital network traffic, and create 2 "encapsulates" relationship with the 2 other network traffic
    • BEFORE --> no store update event but NULL in the stream events, NOW -> no error, correct values in the stream events

Copy link
Member Author

Choose a reason for hiding this comment

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

None of the input names modified here are exposed in the graphql API

The refs can only be created through stixRefRelationShipAdd, using relationship_type key and it does not need to change there.

@@ -32,16 +32,24 @@ steps:
commands:
- apk add build-base git libffi-dev cargo
- pip3 install --upgrade setuptools
- cd opencti-platform
- OPENCTI_COMMIT=$(git rev-parse --short HEAD)
- echo [INFO] using opencti@$DRONE_COMMIT_BRANCH:$OPENCTI_COMMIT
Copy link
Member Author

Choose a reason for hiding this comment

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

just an improvement on the way, to finally have a clear feedback on what is the precise version used.

Comment on lines -10166 to +10183
sample: String
analysisSample: String
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only breaking change to the API.

All other renaming are on attribute never exposed in the API for now.

Copy link
Member

Choose a reason for hiding this comment

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

Why not objectSample?

Comment on lines -604 to +603
if (dst === INPUT_FROM && isStixRefRelationship(type)) {
if (dst === 'from' && isStixRefRelationship(type)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

this one was tricky.

"from" is a key used in 2 different context: it's the "from" of a relationship, and the "from" in an email message.

INPUT_FROM was defined for use with email message only, but it was also imported and used in places related to relationship.

Now that we renamed for email to emailFrom it's not working anymore for relationships. But it was never meant to work like that in the first place.

Copy link
Member

Choose a reason for hiding this comment

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

Now that email is now on INPUT_EMAIL_FROM, are you sure is still needed to not used the constant?

Copy link
Member Author

Choose a reason for hiding this comment

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

Most of the time the constant INPUT_NAME was not used, its' the string "from".
It was an input for email, but as for relationship it's not in any schema def, it's not an input.
We think it's an old confusion (email 'from' being used in place where we actually meant "from" of a relationship).

We removed the constant INPUT_NAME. It's not used in any schema def.

Copy link
Member

Choose a reason for hiding this comment

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

This part was causing the test "should all elements correctly deleted" in middleware-test to fail, because the "from" was not resolved for one of the entity (it was a stix ref relationship). and yes we think "INPUT_FROM" was used by mistake because it was "from" until we changed it to "emailFrom", since it was an input specific to email message. And it was the only place where it was used as a constant, in all other places in middleware we use the string 'from' directly.

@labo-flg labo-flg marked this pull request as ready for review February 22, 2024 16:58
export const INPUT_TO = 'to';
export const INPUT_CC = 'cc';
export const INPUT_BCC = 'bcc';
export const INPUT_SENDER = 'emailSender';
Copy link
Member

Choose a reason for hiding this comment

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

I thought we talk about pushing the objectXXX convention

Copy link
Member Author

Choose a reason for hiding this comment

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

the convention objectXXX produces the change contains -> objectContains
but objectContains was an old filter key still renamed on the fly to objects, so we can't use objectContains

one thing leading to another, we thought it would be better to prefix with the entity they're used for as per the schema description. It's the case for a lot of other keys.

@labo-flg labo-flg self-assigned this Feb 23, 2024
@labo-flg labo-flg added the filigran team use to identify PR from the Filigran team label Feb 23, 2024
@lndrtrbn lndrtrbn self-requested a review February 26, 2024 14:14
Kedae
Kedae previously requested changes Feb 27, 2024
Copy link
Member

@Kedae Kedae left a comment

Choose a reason for hiding this comment

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

Need Julien eye on that

@SouadHadjiat
Copy link
Member

Related python client PR open for malwareAnalysis : OpenCTI-Platform/client-python#563

@richard-julien richard-julien merged commit dd88a22 into master Feb 27, 2024
4 of 6 checks passed
@richard-julien richard-julien deleted the issue/6056 branch February 27, 2024 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filigran team use to identify PR from the Filigran team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Worker error when importing Network-Traffic object with nested properties
5 participants