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

PyPi Simple endpoint end slash handling #8817

Closed
dlouzan opened this issue Feb 22, 2021 · 7 comments · Fixed by #8879
Closed

PyPi Simple endpoint end slash handling #8817

dlouzan opened this issue Feb 22, 2021 · 7 comments · Fixed by #8879
Labels
datasource:pypi priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others type:feature Feature (new functionality)

Comments

@dlouzan
Copy link

dlouzan commented Feb 22, 2021

What Renovate type, platform and version are you using?

Self-hosted latest

Describe the bug

At the moment I'm not sure if this is an actual bug, but wanted to open a discussion about it.

While combining renovate self-hosted with JFrog's artifactory and the PyPi Simple index, renovate is not being able to find dependencies on Artifactory due to handling of the end slash in the index endpoint.

The issue happens in combination with https://www.jfrog.com/jira/browse/RTFACT-14235, which basically is a problem on Artifactory redirecting HTTPS to HTTP (yeah 😒). So for instance:

# This works
curl -v https://internal.domain/artifactory/api/pypi/pypi-all/simple/

# This is redirected to HTTP with slash at the end
curl -v https://internal.domain/artifactory/api/pypi/pypi-all/simple
...
< HTTP/1.1 302 Found
< Date: Mon, 22 Feb 2021 19:36:40 GMT
< Server: Artifactory/x.x.x
< X-Artifactory-Id: xxx
< Location: http://internal.domain/artifactory/api/pypi/pypi-all/simple/
< Content-Length: 0

While this looks to me an artifactory issue, the relevant PEP itself points to all addresses ending in slash, so at the moment I'm not sure where the issue really is. Should per spec all URLs end in slash?

But I'm relatively sure, if renovate appended the slash, everything would work because there wouldn't be any redirects involved 🙇

I'd be happy for some guidance or opinions.

/cc @max-wittig @fh1ch @nejch

@dlouzan
Copy link
Author

dlouzan commented Feb 22, 2021

The PEP says:

All URLs which respond with an HTML5 page MUST end with a / and the repository SHOULD redirect the URLs without a / to add a / to the end.

While Artifactory clearly behaves incorrectly here by redirecting an HTTPS to HTTP, I think renovate would be safe to append / ensure / to all simple requests?

@viceice viceice added datasource:pypi priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others status:requirements Full requirements are not yet known, so implementation should not be started type:feature Feature (new functionality) labels Feb 23, 2021
@github-actions
Copy link
Contributor

This issue has been labeled with status:requirements. This indicates that we don't know enough to start work and further requirements or a reproduction are needed first.

This label will be replaced with status:ready once all requirements and reproductions necessary to start work have been met.

If it's not clear what is missing to move this issue forward, ask for clarification in a new comment. If you think we already have what we need to move forward, mention this in a new comment.

@viceice
Copy link
Member

viceice commented Feb 23, 2021

I think this can be easily fixed by ensureEndingSlash on lookupName here:

dependency = await getSimpleDependency(lookupName, hostUrl);

@viceice viceice added status:ready and removed status:requirements Full requirements are not yet known, so implementation should not be started labels Feb 23, 2021
@rarkins
Copy link
Collaborator

rarkins commented Feb 23, 2021

Where is the URL coming from? e.g. Renovate config, requirements.txt, etc?

Is it the plain registry url that's getting a 302, or one which we construct with dependency name too?

@viceice viceice closed this as completed Feb 23, 2021
@viceice viceice reopened this Feb 23, 2021
@viceice
Copy link
Member

viceice commented Feb 23, 2021

Url is constructed here:

const lookupUrl = url.resolve(hostUrl, `${packageName}`);
const dependency: ReleaseResult = { releases: null };
const response = await http.get(lookupUrl);

so packageName needs an ending slash here.

@nejch
Copy link
Contributor

nejch commented Feb 23, 2021

Just one thing to keep in mind also is that some proxies don't handle double/multiple slashes very well (mostly Apache I think, resulting in 404), so it should only append if needed. I know python-gitlab is doing the opposite (stripping trailing slashes from base urls) for this reason (python-gitlab/python-gitlab#1027).

@viceice
Copy link
Member

viceice commented Feb 23, 2021

Just one thing to keep in mind also is that some proxies don't handle double/multiple slashes very well (mostly Apache I think, resulting in 404), so it should only append if needed. I know python-gitlab is doing the opposite (stripping trailing slashes from base urls) for this reason (python-gitlab/python-gitlab#1027).

That's why we have a util function for it 😉

export function ensureTrailingSlash(url: string): string {
return url.replace(/\/?$/, '/');
}

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
datasource:pypi priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others type:feature Feature (new functionality)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants