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

XSD download fails with "Server returned HTTP response code: 403" #429

Closed
Gama11 opened this issue Feb 22, 2021 · 11 comments · Fixed by eclipse-lemminx/lemminx#994 or enxio/lsp4xml#117
Assignees
Labels
bug Something isn't working validation
Milestone

Comments

@Gama11
Copy link

Gama11 commented Feb 22, 2021

<?xml version="1.0" encoding="utf-8"?>
<project 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="https://lime.software/xsd/project-1.0.0.xsd">

</project>

Causes the following error output in the XML output channel:

[Info  - 20:11:06] Feb 22, 2021 08:11:06 org.eclipse.lemminx.uriresolver.CacheResourcesManager lambda$downloadResource$0()
Message: Downloading https://lime.software/xsd/project-1.0.0.xsd to C:\Users\<User>\.lemminx\cache\https\lime.software\xsd\project-1.0.0.xsd...
[Error - 20:11:06] Feb 22, 2021 08:11:06 org.eclipse.lemminx.uriresolver.CacheResourcesManager lambda$downloadResource$0()
Message: Error while downloading https://lime.software/xsd/project-1.0.0.xsd to C:\Users\<User>\.lemminx\cache\https\lime.software\xsd\project-1.0.0.xsd : [java.io.IOException] Server returned HTTP response code: 403 for URL: https://lime.software/xsd/project-1.0.0.xsd
[Info  - 20:11:06] Feb 22, 2021 08:11:06 org.eclipse.lemminx.uriresolver.CacheResourcesManager getResource()
Message: Ignored unavailable schema URI: https://lime.software/xsd/project-1.0.0.xsd

The 403 error response is very curious, as I have no issues viewing https://lime.software/xsd/project-1.0.0.xsd in my browser.
curl https://lime.software/xsd/project-1.0.0.xsd also has no complaints.


VSCode 1.53.2, Windows 10 20H2, vscode-xml 0.15.0

@datho7561
Copy link
Contributor

Hello! I can't seem to reproduce the issue. I have a few questions that might help to pin down the issue. Does this happen every time you open the document, or just once? Are you behind a proxy for internet access? Are you running the binary or the Java version of the server?

@Gama11
Copy link
Author

Gama11 commented Feb 22, 2021

Does this happen every time you open the document, or just once?

If I close and reopen the document, it doesn't seem to attempt the download again, it only logs "Ignored unavailable schema...". Reloading VSCode triggers the entire output channel sequence from above.

Are you behind a proxy for internet access?

No.

Are you running the binary or the Java version of the server?

Whatever the default is I guess? I just installed it from the VSCode marketplace and haven't configured anything in settings.json.

@datho7561
Copy link
Contributor

Okay. Thanks for the information. I can't seem to reproduce the issue. Are you using the default settings for vscode-xml? Would you be able to search for "LemMinX Server info:" in the XML Support output, then copy and paste the list of infos?

@Gama11
Copy link
Author

Gama11 commented Feb 23, 2021

Are you using the default settings for vscode-xml?

Yes, as I said.

Would you be able to search for "LemMinX Server info:" in the XML Support output, then copy and paste the list of infos?

LemMinX Server info:
 - Version : 0.15.0
 - Java : C:\Program Files\Amazon Corretto\jdk1.8.0_265\jre
 - VM Version : 25.265-b01
 - Git cb5fba5 - [maven-release-plugin] prepare release 0.15.0

@datho7561
Copy link
Contributor

Okay. Thank you!

@datho7561 datho7561 added the bug Something isn't working label Feb 23, 2021
@datho7561 datho7561 self-assigned this Feb 23, 2021
@datho7561
Copy link
Contributor

I'm able to reproduce now.

@datho7561
Copy link
Contributor

Under Java 11, I didn't get the bug, but under Java 8 in Windows and Linux I get the same thing.

@Gama11
Copy link
Author

Gama11 commented Feb 23, 2021

That's interesting. I'm not even sure how it ends up using that JDK 8, the one in my PATH is a JDK 14. If I set "xml.java.home" to that it indeed works.

@angelozerr
Copy link
Contributor

angelozerr commented Feb 24, 2021

Problem comes from with URLConnection use https://github.com/eclipse/lemminx/blob/a54317a7490f35a3fd34a2acd70f94fc5ce289e8/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/uriresolver/CacheResourcesManager.java#L169

The problem can be reproduced easily with a simple main:

package test;

import java.net.URL;
import java.net.URLConnection;

public class Main {

	public static void main(String[] args) throws Exception {
		String actualURI = "https://lime.software/xsd/project-1.0.0.xsd";
		URL url = new URL(actualURI);
		URLConnection conn = url.openConnection();
		conn.getInputStream();
	}
}

If you execute this code in Java 11 it's working although in Java 1.8 it throws a 403 error.

It's seems that it's a user agent request matter.

In Java 8, the user agent is Java/1.8 which throws a 403 error, although in Java 11 the user agent is Java/11 and it's working. It seems that 1. is not accepted. (Why I don't know?)

You can experiment that with the following code executed in Java 1.8:

package test;

import java.net.URL;
import java.net.URLConnection;

public class Main {

	public static void main(String[] args) throws Exception {
		String actualURI = "https://lime.software/xsd/project-1.0.0.xsd";
		URL url = new URL(actualURI);
		URLConnection conn = url.openConnection();
		conn.addRequestProperty("User-Agent", "Java/1.8"); // throws a 403
		conn.getInputStream();
	}
}

should throw a 403, although the following code should work:

package test;

import java.net.URL;
import java.net.URLConnection;

public class Main {

	public static void main(String[] args) throws Exception {
		String actualURI = "https://lime.software/xsd/project-1.0.0.xsd";
		URL url = new URL(actualURI);
		URLConnection conn = url.openConnection();
		conn.addRequestProperty("User-Agent", "Java/11"); // should work
		conn.getInputStream();
	}
}

A fix could catch the 403 error and recreate the connection by forcing the User Agent like conn.addRequestProperty("User-Agent", "LemMinX");

@fbricon
Copy link
Collaborator

fbricon commented Feb 24, 2021

No don't catch the 403. always set the user agent to LemMinX. That'll take care of downloading files hosted on cloudflare managed servers

@rgrunber
Copy link
Member

curl -A "Java/1.8" -I https://lime.software/xsd/project-1.0.0.xsd
.. 403

:|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working validation
Projects
None yet
5 participants