programing tip

Apache에서 인코딩 된 슬래시를 허용해야합니다.

itbloger 2020. 11. 10. 07:55
반응형

Apache에서 인코딩 된 슬래시를 허용해야합니다.


현재 URL 내에 URL을 배치하려고합니다. 예를 들면 :

http://example.com/url/http%3A%2F%2Fwww.url2.com

내가 한 URL을 인코딩해야한다는 것을 알고 있지만 이제 404내 앱이 아닌 서버에서 오류가 다시 발생합니다. 내 문제는 아파치에 있으며 AllowEncodedSlashes On지시문으로 해결할 수 있다고 생각 합니다.

httpd.conf의 맨 아래에 지시문을 적용하려고 시도했지만 다음에 무엇을 해야할지 잘 모르겠습니다. 올바른 위치에 배치하고 있습니까? 그렇다면 다른 해결책이있는 사람이 있습니까?


이 문제는 Apache Bug 35256과 관련이 없습니다. 오히려 Bug 46830과 관련이 있습니다.이 AllowEncodedSlashes설정은 가상 호스트에 의해 상속되지 않으며 가상 호스트는 Ubuntu에있는 것과 같은 많은 기본 Apache 구성에서 사용됩니다. 해결 방법은 컨테이너 ( Ubuntu) AllowEncodedSlashes내부에 설정 을 추가하는 것 입니다.<VirtualHost>/etc/apache2/sites-available/default

버그 35256 : %2FPATH_INFO에서 AllowEncodedSlashes디코딩됩니다 (디코딩이 수행되지 않는다는 문서 ).

버그 46830 : AllowEncodedSlashes On글로벌 컨텍스트 에서이 설정 되면 가상 호스트에서 상속되지 않습니다. AllowEncodedSlashes On모든 <VirtalHost>컨테이너에 명시 적으로 설정해야합니다 .

다른 구성 섹션이 병합되는 방법에 대한 문서는 다음과 같습니다.

섹션 내부 <VirtualHost>섹션은 가상 호스트 정의 외부의 해당 섹션 뒤에 적용됩니다. 이를 통해 가상 호스트가 기본 서버 구성을 재정의 할 수 있습니다.


나는 다른 문제에 대해이 게시물을 계속 보았습니다. 빨리 설명하겠습니다.

나는 동일한 스타일의 URL을 가지고 있었고 그것을 프록시하려고했습니다.

예 : /example/다른 서버 에서 프록시 요청 .

/example/http:%2F%2Fwww.someurl.com/

문제 1 : Apache가 잘못된 URL이라고 생각 함

솔루션 : AllowEncodedSlashes Onhttpd.conf

문제 2 : Apache가 인코딩 된 슬래시를 디코딩합니다.

솔루션 : AllowEncodedSlashes NoDecodehttpd.conf (Apache 2.3.12+ 필요)

문제 3 : 재 인코딩에 mod_proxy를 시도 (이중 인코딩) 변경 URL %2F%252F(예. /example/http:%252F%252Fwww.someurl.com/)

솔루션 : 키워드 httpd.conf사용 하여 프록시를 통해 원시 URL을 전달하십시오.ProxyPassnocanon

ProxyPass http://anotherserver:8080/example/ nocanon

httpd.conf 파일 :

AllowEncodedSlashes NoDecode

<Location /example/>
  ProxyPass http://anotherserver:8080/example/ nocanon
</Location>

참고:


이 문제에 대해서도 많은 시간을 낭비했습니다. 파티에 조금 늦었지만 이제 해결책이있는 것 같습니다.

이 스레드에 따라 아파치에 버그가 AllowEncodedSlashes On있어 404 가 있으면 404를 방지하지만 RFC에 따라 잘못된 슬래시를 실수로 디코딩 합니다.

이 주석은 다음과 같은 솔루션을 제공합니다.

AllowEncodedSlashes NoDecode

모든 번거 로움을 감안하여 base64_encoding과 urlencoding을 선택했습니다. 아파치 서버 설정을 속이거나 버그 보고서를 보지 않고도 작동합니다. 또한 쿼리 섹션에 URL을 입력하지 않고도 작동합니다.

$enc_url = urlencode(base64_encode($uri_string));

그리고 그것을 되찾기 위해

$url = base64_decode(urldecode($enc_url));

http://example.com/admin/supplier_show/8/YWRtaW4vc3VwcGxpZXJz

http://example.com/admin/supplier_show/93/YWRtaW4vc3VwcGxpZXJzLzEwMA%3D%3D


약간의 테스트와 Apache의 버그를 살펴본 결과, 다른 포럼에서 솔루션을 제공 했음에도 불구하고 이것은 Apache에서 해결되지 않은 문제라는 결론을 내 렸습니다. 버그 참조 : https://issues.apache.org/bugzilla/show_bug.cgi?id=35256

나를 위해 작동하는 해결 방법은 이스케이프 된 슬래시를 포함 할 수있는 항목이 경로 대신 URI의 쿼리 섹션에 있도록 URI를 리팩터링하는 것입니다. 내 테스트에 따르면 AllowEncodedSlashes 및 AcceptPathInfo 설정에 관계없이 Apache에 의해 필터링되지 않습니다.

그래서: http://test.com/url?http%3A%2F%2Fwww.url2.com

또는: http://test.com/url?theURL=http%3A%2F%2Fwww.url2.com

대신에: http://test.com/url/http%3A%2F%2Fwww.url2.com

This means an architecture change for our project, but it seems unavoidable. Hope you found a solution.


I'm getting the same problem with "AllowEncodedSlashes On", and have tried placing the directive in a couple different places: apache2.conf, httpd.conf, and inside a section, as per an example at http://www.jampmark.com/web-scripting/5-solutions-to-url-encoded-slashes-problem-in-apache.html.

If you haven't already, you might want to set your logging level to debug (another directive) and see if you get the error:

found %2f (encoded '/') in URI (decoded='/url/http://www.url2.com'), returning 404

other not found errors don't provide this info in the logs. Just another diagnostic...

Good luck (to both of us)!


Replace %2F with %252F at the client side.

This is the double-encoded form of the forward slash.

So when it reaches the server and gets prematurely decoded it will decode it to %2F which is exactly what you want.

참고URL : https://stackoverflow.com/questions/4390436/need-to-allow-encoded-slashes-on-apache

반응형