Skip to content

Conversation

@smalho01
Copy link
Collaborator

Describe your changes

Check the ETASU status at the dispense authorization endpoint, basic fill in for NCPDP messages using JSON for now (will change to NCPDP XML once we receive spec) and send a communication resource to the FHIR EHR server for the prescriber to see.

Issue ticket number and Jira link

REMS-856

Checklist before requesting a review

  • I have performed a self-review of my code
  • Ensure the target / base branch for any feature PR is set to dev not main (the only exception to this is releases from dev and hotfix branches)

Checklist for conducting a review

  • Review the code changes and make sure they all make sense and are necessary.
  • Pull the PR branch locally and test by running through workflow and making sure everything works as it is supposed to.

Workflow

Owner of the Pull Request will be responsible for merge after all requirements are met, including approval from at least one reviewer. Additional changes made after a review will dismiss any approvals and require re-review of the additional updates. Auto merging can be enabled below if additional changes are likely not to be needed. The bot will auto assign reviewers to your Pull Request for you.

logger.info(`Dispense authorization check for case: ${caseNumber}`);

// Find the REMS case
const remsCase = await remsCaseCollection.findOne({ case_number: caseNumber });

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a user-provided value.

Copilot Autofix

AI 25 days ago

The best way to fix the problem is to ensure that the user-supplied caseNumber is interpreted strictly as a literal value in the MongoDB query. This can be done by either validating that caseNumber is a string (or other expected primitive type), or by wrapping it in the $eq operator in the query. The $eq operator ensures that even if an attacker submits a crafted object value, it will not be executed as a query operator but only as a value to match exactly.

To implement the change, in src/lib/dispense_authorization.ts, update the line where findOne is called (remsCaseCollection.findOne({ case_number: caseNumber })) to instead use { case_number: { $eq: caseNumber } }. Optionally, you may add a validation to ensure caseNumber is a string, but using $eq is sufficient and straightforward.

No new imports are required.

Suggested changeset 1
src/lib/dispense_authorization.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/lib/dispense_authorization.ts b/src/lib/dispense_authorization.ts
--- a/src/lib/dispense_authorization.ts
+++ b/src/lib/dispense_authorization.ts
@@ -25,7 +25,7 @@
     logger.info(`Dispense authorization check for case: ${caseNumber}`);
 
     // Find the REMS case
-    const remsCase = await remsCaseCollection.findOne({ case_number: caseNumber });
+    const remsCase = await remsCaseCollection.findOne({ case_number: { $eq: caseNumber } });
 
     if (!remsCase) {
       logger.warn(`REMS case not found: ${caseNumber}`);
EOF
@@ -25,7 +25,7 @@
logger.info(`Dispense authorization check for case: ${caseNumber}`);

// Find the REMS case
const remsCase = await remsCaseCollection.findOne({ case_number: caseNumber });
const remsCase = await remsCaseCollection.findOne({ case_number: { $eq: caseNumber } });

if (!remsCase) {
logger.warn(`REMS case not found: ${caseNumber}`);
Copilot is powered by AI and may make mistakes. Always verify output.
@smalho01 smalho01 committed this autofix suggestion 25 days ago.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

merged this in

…om user-controlled sources

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
};


let ehrEndpoint = config.fhirServerConfig?.auth?.resourceServer;
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to use the previous hooks calls to the REMS Admin to determine who to send the Communication to. We do not want to send it to a preconfigured EHR. We can do this as a separate task if that makes more sense to do, at least add a todo here in the code. With the case we need to store who sent the request originally. This should be easy to save, but we may need to have the intermediary keep information about all of the calls it makes to know who to send the Communication back to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants