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

SparkJava - failed to validate http methods for Static files #1204

Open
Prashantha-AV opened this issue Dec 10, 2020 · 1 comment
Open

SparkJava - failed to validate http methods for Static files #1204

Prashantha-AV opened this issue Dec 10, 2020 · 1 comment

Comments

@Prashantha-AV
Copy link

HI,

Need help on static files

Issue : When the application startup, the static file can be accessed with any(GET,POST, XXX) http method
Application fails in Vulnerability scan as below
identified: - Verb tampering, Only allow required http methods e.g. get, post.

Spark Java version : spark-core:2.7.2
Server: Jetty(9.4.14.v20181114)

is it possible to add filter or some other alternative to stop accessing the static information from CURL or POSTMAN ?

Sample reproducer

import static spark.Spark.halt;
import spark.Service;
public class ServerExample {

    public ServerExample() {
        Service service = Service.ignite().port(4568);
        service.staticFiles.externalLocation("C:\\dev");  //file attached for dev folder

        service.before((req, res) -> {
            System.out.println("Hello:" + req.headers());
        });

        service.get("/", (req, res) -> {
            if (!req.requestMethod().equalsIgnoreCase("GET")) {
                halt(401, "invalid Http method");
            }
            return null;
        });
    }
    public static void main(String[] args) {
        new ServerExample();
    }
}

reproduce issue from CURL
1.

curl -X XYZ --insecure http://localhost:4568/
Response -> <!doctype html>Welcome

curl -X XYZ --insecure http://localhost:4568/manifest.json
Response ->
{
"icons": [
{
"src": "favicon.png",
"sizes": "48x48",

The XYZ above call is invalid HTTP method.

The app should not respond to any invalid http method, adding filter "/" is not considered.

Could any help to fix this.
dev.zip

@Prashantha-AV Prashantha-AV changed the title SparkJava - failed validate http methods for Static files SparkJava - failed to validate http methods for Static files Dec 10, 2020
@senyast4745
Copy link

senyast4745 commented Feb 17, 2021

@Prashantha-AV @perwendel
Hi. I think the correct behavior is to return a 405 code if the file is found, but the http method is not supported. Do you agree?

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

No branches or pull requests

2 participants