Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

Riscue
Copy link
Contributor

@Riscue Riscue commented Dec 7, 2023

What type of PR?

Enhancement

What does this PR do?

Checks TXT records for SPF, DKIM, DMARC same as MX record checker

Copy link
Contributor

mergify bot commented Dec 7, 2023

Thanks for submitting this pull request.
Bors-ng will now build test images. When it succeeds, we will continue to review and test your PR.

bors try

Note: if this build fails, read this.

bors-mailu bot added a commit that referenced this pull request Dec 7, 2023
@bors-mailu
Copy link
Contributor

bors-mailu bot commented Dec 7, 2023

try

Build succeeded:

Copy link
Contributor

@ghostwheel42 ghostwheel42 left a comment

Choose a reason for hiding this comment

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

Hi. Thanks for your contribution.
I was thinking about doing the checks asynchronously (by having a "spinner" image and requesting the check via src="" returning a good or bad image), but this is a good start.
I didn't run in yet, but I think the regex should be changed.

core/admin/mailu/models.py Outdated Show resolved Hide resolved
core/admin/mailu/models.py Show resolved Hide resolved
@Riscue
Copy link
Contributor Author

Riscue commented Dec 7, 2023

Hi. Thanks for your contribution. I was thinking about doing the checks asynchronously (by having a "spinner" image and requesting the check via src="" returning a good or bad image), but this is a good start. I didn't run in yet, but I think the regex should be changed.

If we do this asynchronously, I will explicitly check all dns entries as well as auto-configuration entries.

And check methods could return states like exist-correct, exist-unknown, not exist? Any thought?

@ghostwheel42
Copy link
Contributor

Sorry for the delay. At first I thought the simplest way to implement this would be a route to check dns entries like .../check/dkim returning a single location header pointing to an image (good or bad).
The web page would have a spinning circle as lowsrc and the check as src.
Another way would be to do it via JS/jquery and a jsonp response. This could return more precise error messages and the values of the actual records.

Alex

@ghostwheel42 ghostwheel42 added type/enhancement Enhances existing functionality priority/p2 Minor bug / Could have python Pull requests that update Python code labels Dec 22, 2023
Copy link
Contributor

mergify bot commented Feb 22, 2024

Thanks for submitting this pull request.
Bors-ng will now build test images. When it succeeds, we will continue to review and test your PR.

bors try

Note: if this build fails, read this.

bors-mailu bot added a commit that referenced this pull request Feb 29, 2024
@bors-mailu
Copy link
Contributor

bors-mailu bot commented Feb 29, 2024

try

Build succeeded:

@mergify mergify bot dismissed ghostwheel42’s stale review October 8, 2024 11:34

Pull request has been modified.

@Riscue
Copy link
Contributor Author

Riscue commented Oct 8, 2024

Sorry for the delay. At first I thought the simplest way to implement this would be a route to check dns entries like .../check/dkim returning a single location header pointing to an image (good or bad). The web page would have a spinning circle as lowsrc and the check as src. Another way would be to do it via JS/jquery and a jsonp response. This could return more precise error messages and the values of the actual records.

Alex

Done via async image loading. Please check the routes for images and css changes

@Riscue
Copy link
Contributor Author

Riscue commented Oct 8, 2024

bors try

@bors-mailu
Copy link
Contributor

bors-mailu bot commented Oct 8, 2024

🔒 Permission denied

Existing reviewers: click here to make Riscue a reviewer

@Riscue
Copy link
Contributor Author

Riscue commented Oct 10, 2024

@ghostwheel42 Hey alex bors stuck, could you please force for retry and review new commits

@ghostwheel42
Copy link
Contributor

bors try

bors-mailu bot added a commit that referenced this pull request Oct 10, 2024
@bors-mailu
Copy link
Contributor

bors-mailu bot commented Oct 10, 2024

try

Build failed:

@Riscue
Copy link
Contributor Author

Riscue commented Oct 16, 2024

@ghostwheel42 Hey alex fixed a bug, please retry

@ghostwheel42
Copy link
Contributor

bors try

bors-mailu bot added a commit that referenced this pull request Oct 16, 2024
@bors-mailu
Copy link
Contributor

bors-mailu bot commented Oct 16, 2024

try

Build succeeded:

@Riscue
Copy link
Contributor Author

Riscue commented Oct 21, 2024

Hey Alex @ghostwheel42 it is done actually, what should i do next?

core/admin/mailu/models.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ghostwheel42 ghostwheel42 left a comment

Choose a reason for hiding this comment

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

Hi @Riscue and sorry for being quiet for so long.

I think this is a good start at checking if the DNS config is like the one proposed.

Of course it is not a 100% check as some mx tools do and it will probably yield false-positives and false negatives, but the people using their own records should know what they are doing (for example when using "include:" in the spf records).

I would move the routes below the 'details' path, so instead of '/domain/<domain_name>/check/mx' I would use '/domain/details/<domain_name>/check/mx'.
This will allow to strip the '../../domain/' and '../../alternative/' from the templates.

@nextgens Do you think we need to do some kind of caching or rate limiting on the check routes to avoid abuse by doing lots of dns queries?

I think after the changes are done we could start testing this in the master branch.

""" checks if DMARC record for domain points to mailu host """
try:
return any(
rset.to_text().startswith('"v=DMARC1;')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
rset.to_text().startswith('"v=DMARC1;')
rset.to_text().strip('"').split(';')[0].strip() == 'v=DMARC1'

This is more robust - also use this for the report check, as there do not need to be any other tags defined.

app_config_domain = app.config['DOMAIN']
try:
return any(
rset.to_text().startswith('"v=DMARC1;')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
rset.to_text().startswith('"v=DMARC1;')
rset.to_text().strip('"').split(';')[0].strip() == 'v=DMARC1'

""" checks if DMARC record for domain points to mailu host """
try:
return any(
rset.to_text().startswith('"v=DMARC1;')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
rset.to_text().startswith('"v=DMARC1;')
rset.to_text().strip('"').split(';')[0].strip() == 'v=DMARC1'

app_config_domain = app.config['DOMAIN']
try:
return any(
rset.to_text().startswith('"v=DMARC1;')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
rset.to_text().startswith('"v=DMARC1;')
rset.to_text().strip('"').split(';')[0].strip() == 'v=DMARC1'

Copy link
Contributor

@nextgens nextgens left a comment

Choose a reason for hiding this comment

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

@ghostwheel42 I'm not worried about it. DNS has a built-in cache mechanism with TTL, this will go no further than the local resolver.

What needs to be checked is how timeouts are handled. Browsers only allow so many parallel connections... if we block awaiting for a DNS reply for several items on the same page, we may exceed the limit. It may be better to timeout earlier and return some "unknown" png faster... refreshing the page (which could also be done automatically) would then display the right results

try:
hostnames = app.config['HOSTNAMES'].replace(',', '|')
return any(
re.search(f'^"v=spf1 mx a:({hostnames}) [?+-~]all"$', rset.to_text())
Copy link
Contributor

Choose a reason for hiding this comment

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

[?+-~] without escapes and without marking the string as a regexp pattern? - will break for sure

try:
hostnames = app.config['HOSTNAMES'].replace(',', '|')
return any(
re.search(f'^"v=spf1 mx a:({hostnames}) [?+-~]all"$', rset.to_text())
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

return False


def check_spf(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's avoid code duplication please, make those methods static or something

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

Labels

priority/p2 Minor bug / Could have python Pull requests that update Python code type/enhancement Enhances existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.