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

Submission version redirect is infinite loop if instance ID is encoded #882

Open
matthew-white opened this issue May 19, 2023 · 0 comments
Labels

Comments

@matthew-white
Copy link
Member

For several endpoints for the logical submission, if you specify the instance ID of a submission edit, Backend will redirect to the corresponding submission version endpoint:

// if we match the logical id, we stick around. otherwise we redirect.
const getOrRedirect = (Forms, Submissions, { params, auth, originalUrl, queryOptions }) =>
Promise.all([
getForm(params, Forms),
Submissions.getByIds(params.projectId, params.formId, params.instanceId, draft, queryOptions)
])
.then(([ form, maybeSub ]) => Promise.all([
auth.canOrReject('submission.read', form),
maybeSub.map(resolve).orElseGet(() =>
Submissions.getRootForInstanceId(form.id, params.instanceId, draft)
.then(getOrNotFound)
.then((rootId) => redirect(originalUrl.replace(
`/submissions/${params.instanceId}`,
url`/submissions/${rootId}/versions/${params.instanceId}`
))))
]));

For example, on the QA server, there's a submission edit whose instance ID is uuid:adcaefa3-91d7-4770-a49a-1f5607d0f2f3. The instance ID of the root submission version is uuid:4b2b3e15-5675-4baf-9111-1a548cf312cd. When I request https://test.getodk.cloud/v1/projects/414/forms/children_registration/submissions/uuid:adcaefa3-91d7-4770-a49a-1f5607d0f2f3, the redirect happens as expected. However, if the : in the instance ID is encoded, the redirect doesn't happen: https://test.getodk.cloud/v1/projects/414/forms/children_registration/submissions/uuid%3Aadcaefa3-91d7-4770-a49a-1f5607d0f2f3. Instead, I get an ERR_TOO_MANY_REDIRECTS.

I think the issue is that if the instance ID is encoded in originalUrl, then originalUrl does not contain `/submissions/${params.instanceId}`, because params.instanceId is not encoded. In that case, it doesn't complete the replacement, so it ends up redirecting the user to the same originalUrl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant