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

feat: add inquiries api endpoint for webhook support, add query and f… #247

Merged
merged 2 commits into from
May 21, 2024

Conversation

shaunwarman
Copy link
Contributor

…iltering for admin page

Checklist

  • I have ensured my pull request is not behind the main or master branch of the original repository.
  • I have rebased all commits where necessary so that reviewing this pull request can be done without having to merge it first.
  • I have written a commit message that passes commitlint linting.
  • I have ensured that my code changes pass linting tests.
  • I have ensured that my code changes pass unit tests.
  • I have described my pull request and the reasons for code changes along with context if necessary.

@shaunwarman shaunwarman marked this pull request as draft May 16, 2024 03:36
@shaunwarman shaunwarman marked this pull request as ready for review May 20, 2024 04:44
const references = [messageId];
const subject = findSubject(headerLines);

const is_resolved = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I typically do isResolved and isWebhook

Copy link
Contributor

Choose a reason for hiding this comment

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

But I see why you did it here for simplicity in the create below, which is totally OK

@@ -19,11 +23,24 @@ async function list(ctx) {
};
}

query.$or.push({ is_resolved: { $exists: false } }, { is_resolved: false });
Copy link
Contributor

Choose a reason for hiding this comment

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

Get rid of the $exists and just add an index to is_resolved in the model, e.g. index: true for is_resolved property. When I deploy I will set all existing inquiries to is_resolved: true

Copy link
Contributor

Choose a reason for hiding this comment

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

This should just be:

query.$or.push({ is_resolved: false });

Copy link
Contributor

@titanism titanism left a comment

Choose a reason for hiding this comment

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

Looks awesome.

Here's a quick list of changes needed:

  • Add index: true to the model for is_resolved
  • Remove $exists from $or query (will speed up query - I will ensure that all existing data has boolean value for indexing when I deploy)

The other thing is that since this webhook is open to anyone, we should also at the least ensure that we check the resolved hostname of the connecting IP address that made the webhook request. In this case we should check that it's either mx1.forwardemail.net or mx2.forwardemail.net.

Note that in the code for config/api.js we have this section:

if (RATELIMIT_ALLOWLIST.includes(clientHostname))
ctx.allowlistValue = clientHostname;
else {
const rootClientHostname = parseRootDomain(clientHostname);
if (RATELIMIT_ALLOWLIST.includes(rootClientHostname))
ctx.allowlistValue = rootClientHostname;

This sets a value accessible to you in this middleware of ctx.allowlistValue.

This means you could add to the top of the middleware the following:

if (!ctx.allowlistValue || ![env.MX1_HOST, env.MX2_HOST, env.WEB_HOST].includes(ctx.allowlistValue))
  throw Boom.forbidden(ctx.translateError('INVALID_INQUIRY_WEBHOOK_REQUEST'));

You would need to add to config/phrases.js the INVALID_INQUIRY_WEBHOOK_REQUEST value such as "Webhook request did not originate from a valid hostname".

This is related to the discussion here forwardemail/free-email-forwarding#235 (now that we're actually dogfooding our own webhook payload, which is AWESOME!!!).

In the future we could add webhook payload signature, e.g. https://stackoverflow.com/a/68885281 which would go in the MX server code when we make the webhook request.

@titanism titanism merged commit 1da7f90 into forwardemail:master May 21, 2024
3 of 4 checks passed
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.

None yet

2 participants