-
Notifications
You must be signed in to change notification settings - Fork 72
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
Unhelpful error message for a field name with an initial $ character #608
Comments
@ElectricNroff I am testing this on the dev branch and can't replicate the problem. I did a POST request to /cve/{cve-id}/cna with the request body above and got a 200 response. I'm not sure if I am testing this wrong or missing something would you be able to provide some more information on how to reproduce this issue please? |
"testing this on the dev branch" is probably not the best way to describe a test environment, because the dev branch changes from time to time, and the behavior is specific to the database implementation. cve-services/docker/docker-compose.yml Lines 4 to 5 in faebb7a
says that mongo:3.6.20-xenial is used. The behavior is different with later MongoDB versions, as discussed in the https://www.mongodb.com/docs/manual/core/dot-dollar-considerations/ article (etc.). The production version of CVE Services is anticipated to use Amazon DocumentDB, not MongoDB. You may want to test against cveawg-test.mitre.org for this specific issue of a '$' in a field name. For example, reserving a new CVE ID and then posting the following to https://cveawg-test.mitre.org/api/cve/CVE-2022-####/cna
results in
Simply deleting the '$' and instead sending:
results in:
The error handling isn't identical, but the principle is the same. A '$' in a field name will, most likely, not be supported in production, and the CVE Services code needs to produce a valid error report in this situation. |
I have tried to reproduce this on the test instance, but only see Which is not a helpful message, but does not expose the information reported in this issue. @ElectricNroff please comment with instructions on how to reproduce the Mongo error including on which endpoint it occurs and the specific parameters that you are using |
I've modified this issue to reflect the "not a helpful message" angle, because this is the largest concern that can be reproduced with the current dev branch. The endpoint can be /api/cve/CVE-2022-20001/cna for a POST or PUT request with no parameters. To reproduce, follow the https://github.com/CVEProject/cve-services/blob/f5d656f479cbfdbdd26fb0acd4cd549cae71cb1a/docker/README.md process. It is important to ensure that the database is based on MongoDB 3.x. (Later MongoDB versions have more flexibility on $ characters, but the initial release of CVE Services 2.x may rely on a DocumentDB release that omits that flexibility.) Specifically, one can use these steps to check:
This should show Ubuntu 16.04.7 LTS, which is another name for "xenial" as shown at
This shows that version 3.6.20 is being used. The client will receive a 500 Server Error message. A possible solution approach is to add two levels of error checking. First, look for the MongoError: The dollar ($) prefixed field error, and then check for all other instances of MongoError. There may be a few different reasonable design options. One approach is to simply insert the new checks at the beginning of validateJsonSyntax in src/middleware/middleware.js
and then add these to the available error types in src/middleware/error.js
Google searches suggest that DocumentDB, like MongoDB, produces error messages beginning with MongoError but I have not directly tested this. If the change approach outlined above is used with MongoDB 3.6.20, then the client receives a 400 error status with more helpful details than before (the complete error stack is not sent to the client). |
Related to #853 |
Update UNABLE_TO_STORE_CVE_RECORD error message to read something like, "A problem occurred while saving the CVE Record; ensure that x_ values do not start with $" |
JSON 5.0 schema issue #209 has been opened in relation to this issue |
Resolves #608 Improved error message for creating CVE records with $ in X_ values
Summary: this reports an anomaly that may be good to fix before a CVE Services 2.x release, but a fix isn't necessarily required then. The fix approach would be to capture this MongoError somehow, and send the client an error report with a reasonable level of detail.
At the https://github.com/CVEProject/cve-services/tree/b10757d07104a0e8f54ae7c8f78796aeb0dbb12f commit, sending this:
to a cna endpoint results in this in err.stack in errorHandler in src/middleware/middleware.js
The concern is that the client user probably won't know that the dollar sign character is what leads to the 500 Server Error response. Attempts to use an initial dollar sign character for a custom field name are entirely realistic: for example, various documentation about constructing JSON documents recommends $schema as a field name (see the CVEProject/cve-schema#144 issue). DocumentDB does not support $schema - the only allowed names beginning with $ are $db, $id, and $ref.
The text was updated successfully, but these errors were encountered: