Ho inserito quanto segue nel web.xml della mia applicazione per tentare di non consentire PUT, DELETE, ecc .:
<security-constraint>
<web-resource-collection>
<web-resource-name>restricted methods</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>DELETE</http-method>
<http-method>PUT</http-method>
<http-method>SEARCH</http-method>
<http-method>COPY</http-method>
<http-method>MOVE</http-method>
<http-method>PROPFIND</http-method>
<http-method>PROPPATCH</http-method>
<http-method>MKCOL</http-method>
<http-method>LOCK</http-method>
<http-method>UNLOCK</http-method>
<http-method>delete</http-method>
<http-method>put</http-method>
<http-method>search</http-method>
<http-method>copy</http-method>
<http-method>move</http-method>
<http-method>propfind</http-method>
<http-method>proppatch</http-method>
<http-method>mkcol</http-method>
<http-method>lock</http-method>
<http-method>unlock</http-method>
</web-resource-collection>
<auth-constraint />
</security-constraint>
Ok, quindi adesso:
Se faccio una richiesta con il metodo di DELETEottengo un 403 indietro.
Se faccio una richiesta con il metodo di deleteottengo un 403 indietro.
MA
Se faccio una richiesta con il metodo DeLeTeottengo OK!
Come posso fare in modo che non facciano distinzione tra maiuscole e minuscole?
Modifica: lo sto testando con un programma C #:
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "making request";
System.Threading.Thread.Sleep(400);
WebRequest req = WebRequest.Create("http://serverurl/Application/cache_test.jsp");
req.Method = txtMethod.Text;
try
{
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
textBox1.Text = "Status: " + resp.StatusCode;
if (resp.StatusCode == System.Net.HttpStatusCode.OK)
{
WebHeaderCollection header = resp.Headers;
using (System.IO.StreamReader reader = new System.IO.StreamReader(resp.GetResponseStream(), ASCIIEncoding.ASCII))
{
//string responseText = reader.ReadToEnd();
textBox1.Text += "\r\n" + reader.ReadToEnd();
}
}
}
catch (Exception ex)
{
textBox1.Text = ex.Message;
}
}
txtMethod.Textè una casella di testo in cui sto digitando il nome del metodo. Quando c'è un 403, viene generata un'eccezione che viene catturata nel blocco catch.
Cache_test.jsp contiene:
<%
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma","no-cache");
out.print("Method used was: "+request.getMethod());
%>
HttpWebRequestsi è case-sensitive riconoscere e convertire i metodi HTTP standard in maiuscolo. Inoltre, è documentato come consentito solo metodi HTTP standard. L'opzione migliore è utilizzare un flusso TCP non elaborato (ad es. In netcat o PuTTY raw o telnet, ecc.).