OpenCRE icon indicating copy to clipboard operation
OpenCRE copied to clipboard

[Feature request] Create a flexible endpoint for documents

Open stateandprove opened this issue 3 years ago • 3 comments

Current behaviour

There is currently an endpoint /rest/v1/id/xxx-xxx in the application that is responsible for a particular CRE instance. Such an instance has a unique identifier, which is a pair of three-digit numbers separated by a dash. Within the body of this instance there are links to other CREs and documents. If we want to get any linked CRE instance, we can easily get it using the above mentioned endpoint via its id.

Problem

This approach allows us to easily move from parent to child CRE instances and vice versa, but it doesn't include other many-to-many relationships, i.e. between CRE and linked document. It doesn't allow us to get a lot of important information, such as

  • documents of a certain type for a given CRE
  • all CREs linked to this document etc.

Feature Request

Using queryset parameters, we could easily solve both problems with the following requests: /rest/v1/document/?CRE=xxx-xxx solves the first problem and /rest/v1/document/?CRE=xxx-xxx&doctype=Standard solves the second.

So the request is to combine all documents within an endpoint and add the ability to filter document instances using the queryset parameter. This would solve the problem mentioned in the https://github.com/OWASP/common-requirement-enumeration/issues/285 ticket and add other important functionality.

stateandprove avatar Jul 28 '23 17:07 stateandprove

Hi @stateandprove! While investigating this issue I noticed that /rest/v1/id/<creid> retrieves a CRE using get_CREs(), which internally calls __make_cre_links(). This function already loads all nodes related to the CRE from the Links table and exposes them in the links field.

So the relationships between CREs and documents (standards, tools, etc.) already exist in the backend, but currently clients need to fetch /rest/v1/id/<creid> and manually filter the links list.

To address this issue, my understanding is that we could expose this through a new endpoint such as /rest/v1/document, while reusing the existing logic.

Example queries:

  • /rest/v1/document?CRE=<cre-id> → return all documents linked to that CRE
  • /rest/v1/document?CRE=<cre-id>&doctype=Standard → return only documents of a specific type

Implementation-wise, the endpoint could retrieve the CRE via get_CREs(), use the cre.links already populated by __make_cre_links(), filter the linked nodes as needed to extract the documents, optionally filter by doctype, and return the results as JSON.

@northdpole could you please confirm if this approach looks correct?

Abhijeet2409 avatar Mar 09 '26 21:03 Abhijeet2409

there are currently only 2 active doctypes, tool , standard. We don't have any plans of adding further doctypes. Currently only two tools exist in the graph: zap and juiceshop. Given this info, this filtering is irrelevant as in the majority of cases you will receive standard. Further even if you do receive e.g. a zap rule you can filter for standard with this:

cre.links.filter(link => link.document.type === "Standard"); and in python standards = [link for link in cre["links"] if link["document"]["type"] == "Standard"]

given how simple the solution is, adding a whole other feature for a one liner seems excessive.

Happy to listen to arguments for this if there are any

northdpole avatar Mar 13 '26 09:03 northdpole

Thanks @northdpole for the clarification. I wasn’t aware that there are currently only two active doctypes. Given that, filtering directly from cre.links makes sense and a separate endpoint may not be necessary right now.

Also, if possible, could you please provide guidance or feedback on the approaches I suggested in #275 and #470 as well? That would be very helpful, as I want to make sure I’m heading in the right direction. I’m happy to explore other areas of the codebase where contributions would be more useful.

Abhijeet2409 avatar Mar 13 '26 11:03 Abhijeet2409