-
-
Notifications
You must be signed in to change notification settings - Fork 162
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
CORS problem when using /api/view #434
Comments
Hi. Did you set the the |
Sorry, I just realised that the CORS policy only applies to the I prefer not to hardcode |
Thanks, currently Caddy routes all api calls to/from several mailpits and CORS problem can be solved by complicated redirects, |
Does that mean that it will work for you if I apply (fix) the CORS policy to the html route? |
IMHO fixing CORS issue will help to prevent further questions from other users. |
Alternatively you can use endpoint already covered by CORS /api/v1/message/{ID}/part/{PartID} using part id = html for example to return html It will also reduce number of routes to handle on reverse-proxy side. |
I have pushed a change for this to the |
No luck Also tried to manually inject Access-Control-Allow-Origin in caddy response. Same result. Thanks for trying. |
Hmmm, that is unfortunate. OK, what do you think would solve this issue for you? Is it just the |
IMHO hardcoding target="_blank" can be helpful not only in my case. This IFRAME dilemma is obvious and can arise any time soon. To preserve current API structure, solution can be bound to existing /view or /api/v1/message/{ID}/part/{PartID} endpoint using new context. |
I've done a bit more reading, and it is a browser-based security restriction to prevent hacking (you won;t be able to work around it via JavaScript). For instance, if I embedded the Gmail login page within an iframe on my malicious site, and then used JavaScript to listen on the input, and submit the data elsewhere as you log in.
If I was to manipulate the HTML on the Mailpit end, I'm not entirely sure what the best way is. The reason is that while there are DOM-parsing libraries there, they always manipulate more than just the anchor tags, they also create So, I could potentially add a URL variable option, so something like The other option is that your application reads the HTML message data from the AP, and then injects it into your page. I do something similar already in Mailpit itself, injecting the data into a blank iframe using |
mailpit instance is always self hosted, so you can relatively easy attach regex/sed query via api request parameter and DON'T CARE about result. End user should care. srcdoc is not an option. It can be implemented only using Caddy templates, which capabilities are too limited. |
You are embedding the html in an iframe, right? How are you dealing with things like iframe height and styling? Just so I understand 100% - is adding |
Well, it's definitely not a secret.
|
Thanks, but what about my second question of my last message? |
All is working in pre-alpha stage. Feel free to test if you use telegram. Currently there is only one testing pit, so CORS is not a problem for now, but there will be more soon. |
No sorry, I don't have Telegram. Ok, let me think about this a little bit more. There is actually a way an embedded page can call a function (if it exists) in a parent page, which may be the better solution. Sure, you need just the target set, however others may require other functionality too. I've actually done this before in another project, so I'll need to do a bit of digging to see how that worked, and what the limitations (if any) were. At this stage I'm most concerned about security, and also flexibility. |
Glad to hear that you are planning major improvements in project. The most obvious way is to encode <script> section containing payload using base64, then pass it to mailpit in env variable and inject in HTML on api call to /view. Sure some examples will be handy. It can be used directly |
AI generated example using messages
|
HI.
Is it possible to preprocess HTML content to do JS analog of
for external links ?
When showing HTML content in IFRAME external links fail if not preprocessed, but it's not an option when using cross-domain IFRAME. Prohibited by CORS.
Thanks.
The text was updated successfully, but these errors were encountered: