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: explicitly use URLSearchParams when constructing send to email magic links #4138

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

jessicamcinchak
Copy link
Member

@jessicamcinchak jessicamcinchak commented Jan 13, 2025

See #help-issues thread from Tewkesbury here: https://opendigitalplanning.slack.com/archives/C0241GWFG4B/p1736501911947289

Here's what's happening:

  • ✔️ Our submissions log button downloads as expected
  • ✔️ The magic link saved in our email_applications audit table downloads as expected
  • ❌ The magic link when clicked directly from the body of a Gov Notify email does not download as expected and instead throws error: error: "Missing values required to access application files" (email forwarded to devops@)
    • It appears Gov Notify has automatically wrapped the link (eg https://linkprotect.cudasvc.com/url?a={our encoded URL} which fails to properly decode the second query param in the request
    • Eg see amp;localAuthority when inspecting the network request here:
      Screenshot from 2025-01-13 08-56-07

Open questions:

  • Is this bug even on our side of the fence, is this a recent Gov Notify change ?? Can't find anything specific in the docs about this third party service! https://www.notifications.service.gov.uk/using-notify/links-and-URLs
  • Is this isolated to Tewkesbury or their internal network/email applications, why haven't we heard from high-volume send to email teams like Bucks about same?

Changes & testing:

  • I'm hoping that explicitly calling new URLSearchParams() when constructing our magic link may fix this instead of the previous plain string template approach? Any other more robust ideas here?
  • Use the pizza to send a Gov Notify email and check the URL in the email body
    • The magic link downloads as expected for me on the pizza, but is notably NOT wrapped in the linkprotect URL, which likely confirms this is unqiue to Tewkesbury and not Gov Notify as a whole
    • Likely not able to test this any further locally without deploying to prod & asking Tewkesbury to test next live app received or on staging?
  • Unfortunately any solution here is only going to apply to new/future emails and not ones already received, so we'll want to continue pointing councils to the Submissions Logs for those if we hear of others with this issue

@jessicamcinchak jessicamcinchak requested a review from a team January 13, 2025 08:48
Copy link

github-actions bot commented Jan 13, 2025

Removed vultr server and associated DNS entries

email: teamSettings.submissionEmail,
localAuthority: localAuthority,
});
const applicationFilesDownloadLink = `${process.env.API_URL_EXT}/download-application-files/${sessionId}?${params}`;
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
const applicationFilesDownloadLink = `${process.env.API_URL_EXT}/download-application-files/${sessionId}?${params}`;
const applicationFilesDownloadLink = `${process.env.API_URL_EXT}/download-application-files/${sessionId}?${params.toString()}`;

Copy link
Contributor

Choose a reason for hiding this comment

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

Not tested yet (doing so now) but this flagged as an issue with this approach!

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ignore this sorry - when templated this parses to a string natively without .toString() - neat!

Copy link
Member Author

@jessicamcinchak jessicamcinchak Jan 13, 2025

Choose a reason for hiding this comment

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

Exactly 🙂 there's a few inconsistent uses of this around the code base we should cleanup sometime though outside of this

Copy link
Contributor

@RODO94 RODO94 left a comment

Choose a reason for hiding this comment

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

Working for me when testing.

nit: Only thing I would think about adding for robustness is something in the downloadApplicationFiles code to remove these ;amp additions. We can't manage how IT teams wrap ext network requests, and from my view it's likely this could happen again so could be good to start a function now to clean the query params?

Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

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

I think this is an issue with Tewksbury's IT wrapping and incorrectly decoding the URL.

The URL is correct and well formatted - nobody else has reported this and using web APIs (URLSearchParams) is a robust and reliable approach.

We could certainly make this a little bit more robust by -

  • constructing a URL using new URL()
  • validating this URL

However - I don't think this would actually resolve the issue here, just give us a better leg to stand on / more confidence on our side of the fence.

@DafyddLlyr
Copy link
Contributor

BTW - just to be explicit - tested on pizza and working as expected ✅

@jessicamcinchak jessicamcinchak merged commit 5420338 into main Jan 13, 2025
12 checks passed
@jessicamcinchak jessicamcinchak deleted the jess/bug-notify-magic-links branch January 13, 2025 10:00
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