mitre / mitre/HTTP-Proxy-Servlet

Not suitable for dynamic urls calculated for each request

Open
#57 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Java
Stars
1.5k
Forks
557
PR merge metrics
No merged PRs in 30d

Description

Hello:
First, thank you very much for sharing your excellent work.

In my case, I need a proxy for which I get the full (complete) url through a service, like this: http://user:password@10.0.2.40/112/2015_04/file88d78d.mp3

For this case, your servlet does not work unless some methods are overridden, because you code assumes that targetUri and targetHost are fixed and initialized once.

Then my solution working:

    @Override
    public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,
            IOException {
        log.trace("<== {}?{}",request.getRequestURL(),request.getQueryString());
        if (cat.verify(request.getQueryString())) {
            try {
                targetUriObj = new URI(sercomResources.getRecord(request.getParameter("id")).getUrl());
                targetHost = URIUtils.extractHost(targetUriObj);
                log.trace("==> {}",targetUriObj);
                super.service(request, response);
            } catch (Exception e) {
                log.warn("Error obteniendo destino",e);
                throw new ServletException("Trying to process targetUri init parameter: " + e, e);
            }
        } else {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, CAT.CESTEL_AUTH_TOKEN
                    + " missing.");
            log.warn("Intento de acceso prohibido: {}", request.getRequestURI());
        }
    }

    @Override
    protected void initTarget() throws ServletException {
        /**
         * evitar super.initTarget() porque, al no estabecer parámetros en la
         * inicialización, esta llamada genera NPE
         */
        // super.initTarget();
    }

    @Override
    protected String rewriteUrlFromRequest(HttpServletRequest servletRequest) {
        /**
         * super.rewriteUrlFromRequest(servletRequest) genera Url errónea
         */
        return targetUriObj.toString();
    }

Thanks again.
Regards.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the servlet's initTarget and rewriteUrlFromRequest entry points and the request lifecycle around them. Define how a complete destination URL can be selected for each request without requiring subclass overrides, then verify that authenticated requests proxy to that destination while invalid requests still return an error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.