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

fix jinja2 templates #63

Merged
merged 7 commits into from
Jun 27, 2021
Merged

fix jinja2 templates #63

merged 7 commits into from
Jun 27, 2021

Conversation

kucera-lukas
Copy link
Contributor

Hi,

I've been using this library for a few weeks and ran into some issues with the jinja2 integration.

  1. if ConnectionConfig is not instantiated in project parent directory the template validator silently fails and returns None. This results in very confusing error messages because user is not notified about it.

This has been improved so there is proper directory validation and template engine creation is done separately via a method.

  1. There are 3 ways to send data with MessageSchema - via body (no jinja2), html or body (with jinja2). The combination of this with the subtype argument is pretty confusing because it is not very well documented so sometimes emails end up looking very differently from what we would expect.

Created a separate jinja2 argument (template_body) so user knows which argument to use whether they're using jinja2 or not.

Comment on lines 29 to 33
fp = str(v)
if not os.path.exists(fp) or not os.path.isdir(fp) or not os.access(fp, os.R_OK):
raise TemplateFolderDoesNotExist(
f"{v!r} is not a valid path to an email template folder")
return v
Copy link
Collaborator

Choose a reason for hiding this comment

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

hi, thank you for your PR. I think first we need to check TEMPLATE_FOLDER variable is None or not. If a TEMPLATE_FOLDER variable is none we don't check any validations. Otherwise, we validate the template path.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Because the TEMPLATE_FOLDER variable is optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right you are, it has been changed


if os.path.isdir(v) and os.access(v, os.R_OK) and validate_path(v):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why you remove the validate path function? This function check for path traversal security vulnerability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,

i had issues with it when I instantiated ConnectionConfig outside of the parent folder, in the end I had to monkey patch that function to always return True otherwise I would not be able proceed.

I'm not very familiar with the issues of path traversal, I'm going to look in to handling it with pathlib and make a new commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

What are the issues when you instantiate ConnectionConfig outside of the parent folder? Why the previous verification wasn't enough?

@kucera-lukas
Copy link
Contributor Author

Take a look at this improvement, is it sufficient?

I have also removed some of the os checks because that is already done by pydantic DirectoryPath.

@sabuhish
Copy link
Owner

Yes, you are right at first it gets a bit complicated, to have field html and body. But if you properly set it up, this won't be a big problem. Your workaround also seems to be meaningful. thank you for your additional changes. Thanks for your work.Highly appreciated your work!

@sabuhish sabuhish merged commit 56cc89f into sabuhish:master Jun 27, 2021
sabuhish pushed a commit that referenced this pull request Jun 27, 2021
@sabuhish
Copy link
Owner

@kucera-lukas Thank you a lot again for your work! it is released available in 0.4.0.

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.

4 participants