How to Allow ^ character in URLs for tomcat 8.5 - tomcat8

I have a request URL of below format
http://hostname:port/path&param1={"vars":[{"a":"val1","b":"^"},{"c":"val2","d":"^"}]}&param2=Value3|95|3%20-%206%20Months
I changed catalina.properties as per this
stackoverflow question .
But as per tomcat documentation tomcat.util.http.parser.HttpParser.requestTargetAllow property is deprecated and relaxedPathChars and relaxedQueryChars attributes are to be used with Connector tag instead.
However, when i change the xml file to below
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" relaxedQueryChars="^" relaxedPathChars="^"/>
I still get a 400 bad request for the character ^
I am not sure if this is the correct configuration.

Ideally you should always URL-encode your query parameters before sending your request to the server. Read: https://www.talisman.org/~erlkonig/misc/lunatech%5Ewhat-every-webdev-must-know-about-url-encoding/
If you want to go down the relaxedQueryChars route, note that the following chars from your query are also in the set that you ought to add to the exception:
" { } [ ] ^ |
Try this in your server.xml:
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" relaxedQueryChars='^{}[]|"' />
More insight into relaxedQueryChars/relaxedPathChars on the bug ticket 62273. The change was added to all branches of Tomat:
9.0.8
8.5.31
8.0.52
7.0.87
I don't think you need the relaxedPathChars attribute at all (this refers to characters on the URL path). However, the Tomcat team's test results seem to suggest that the following could be used for maximum backward-compatibility:
relaxedPathChars='[]|'
relaxedQueryChars='[]|{}^\`"<>' />
nb/ the first arg to your query should be demarcated by ? not &
http://hostname:port/path?param1=...&param2=...&param3=...

It is required to use unicode instead of the literal < or > characters. Here is the actual relaxedQueryChars value I have in server.xml:
relaxedQueryChars="[]|{}^\`"<>"
[ -> [
] -> ]
| -> |
{ -> {
} -> }
^ -> ^
\ -> \
` -> `
" -> "
< -> <
> -> >

Related

Get the original filename of symlinks in nginx

From another script i got some generated symlinks.
2QGPCKVNG1R -> /anotherdir/movie1.mp4
HJS7J9ND2L5 -> /anotherdir/movie2.mp4
LKA6A9LA7SK -> /anotherdir/movie3.mp4
Displaying these files in NGINX works fine, but I'd like to rename the files at download via content disposition.
Question is how do i get the original filename in nginx variable?
I'm not sure it is possible at all. Is that another script yours or under your control? You can generate an additional nginx config file with a map block with the same script where you can describe a ruleset for mapping an URI value to the Content-Disposition header value (or you can write an additional script to do it with readlink -f <symlink> command:
map $uri $content_disposition {
~/2QGPCKVNG1R$ movie1.mp4;
~/HJS7J9ND2L5$ movie2.mp4;
~/LKA6A9LA7SK$ movie3.mp4;
}
And then include that file to the main nginx config:
include /path/to/content-disposition-map.conf;
server {
...
add_header Content-Disposition $content_disposition;
Another way I see is to use lua-nginx-module and a LUA script like
map $symlink_target $content_disposition {
~/([^/]*)$ $1;
}
server {
...
set_by_lua_block $symlink_target {
local result = io.popen("/bin/readlink -n -f " .. ngx.var.request_filename)
return result:read()
}
add_header Content-Disposition $content_disposition;

Nginx - variable usage (set vs map) context and usage

In Nginx configurations,
I do not know when / where I can use map or set.
I want to do something like this:
I tried using map:
map $host $proxy_destination_include {
default '/etc/nginx/conf.d/params/proxy.params/proxy_params_destination.conf';
}
Or tried using set:
server {
### I want to use this as either a variable / map ###
set $proxy_destination_include /etc/nginx/conf.d/params/proxy.params/proxy_params_destination.conf;
root /var/www/html;
location / {
set_proxy_header X-Forwarded-Location-Site 'static-value';
include $proxy_destination_include;
}
location /otherlocation {
set_proxy_header X-Forwarded-Location-Site 'static-value-2';
include $proxy_destination_include;
}
}
But I think map can only be used when a 'site request' is done? So since it has not been mapped Nginx cannot successfully compile its settings - sudo nginx -t fails
Is there any way to do this using Nginx and 'variables'?

apache nutch to index to solr via REST

newbie in apache nutch - writing a client to use it via REST.
succeed in all the steps (INJECT, FETCH...) - in the last step - when trying to index to solr - it fails to pass the parameter.
The Request (I formatted it in some website)
{
"args": {
"batch": "1463743197862",
"crawlId": "sample-crawl-01",
"solr.server.url": "http:\/\/x.x.x.x:8081\/solr\/"
},
"confId": "default",
"type": "INDEX",
"crawlId": "sample-crawl-01"
}
The Nutch logs:
java.lang.Exception: java.lang.RuntimeException: Missing SOLR URL. Should be set via -D solr.server.url
SOLRIndexWriter
solr.server.url : URL of the SOLR instance (mandatory)
solr.commit.size : buffer size when sending to SOLR (default 1000)
solr.mapping.file : name of the mapping file for fields (default solrindex-mapping.xml)
solr.auth : use authentication (default false)
solr.auth.username : username for authentication
solr.auth.password : password for authentication
at org.apache.hadoop.mapred.LocalJobRunner$Job.runTasks(LocalJobRunner.java:462)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:522)
Was that implemented? the param passing to solr plugin?
You need to create/update a configuration using the /config/create/ endpoint, with a POST request and a payload similar to:
{
"configId":"solr-config",
"force":"true",
"params":{"solr.server.url":"http://127.0.0.1:8983/solr/"}
}
In this case I'm creating a new configuration and specifying the solr.server.url parameter. You can verify this is working with a GET request to /config/solr-config (solr-config is the previously specified configId), the output should contain all the default parameters see https://gist.github.com/jorgelbg/689b1d66d116fa55a1ee14d7193d71b4 for an example/default output. If everything worked fine in the returned JSON you should see the solr.server.url option with the desired value https://gist.github.com/jorgelbg/689b1d66d116fa55a1ee14d7193d71b4#file-nutch-solr-config-json-L464.
After this just hit the /job/create endpoint to create a new INDEX Job, the payload should be something like:
{
"type":"INDEX",
"confId":"solr-config",
"crawlId":"crawl01",
"args": {}
}
The idea is that need to you pass the configId that you created with the solr.server.url specified along with the crawlId and other args. This should return something similar to:
{
"id": "crawl01-solr-config-INDEX-1252914231",
"type": "INDEX",
"confId": "solr-config",
"args": {},
"result": null,
"state": "RUNNING",
"msg": "OK",
"crawlId": "crawl01"
}
Bottom line you need to create a new configuration with the solr.server.url setted instead of specifying it through the args key in the JSON payload.

Extra information in URL redirecting from nolayout.aspx to 404 error page in sitecore website

I just moved my nolayout.aspx to 404 error page inside config file, everything is working fine except the URL. After getting redirect to 404 URL has these extra information :
404?item=%2fservices-and-solutions%2fbusiness-vision%2fit-without-boundaries&layout={00000000-0000-0000-0000-000000000000}&device=Default
I dont want URL having this : &layout={00000000-0000-0000-0000-000000000000}&device=Default
Config settings is :
Rest is fine for me, kindly suggest.
That URL is generated from sitecore. It's not IIS. This one you are getting is when the item doesn't have a layout set. You might also want to look at the not found url. You can set these urls to point to sitecore items in web.config:
Unfortunately, sitecore does not return a Not found status code, so it is better to create your own handler to read the Item and set the status code. See an example here from RUUD VAN FALIER: http://www.partechit.nl/en/blog/2012/11/return-404-status-code-when-itemnotfound-page-is-loaded
Basically, you append a processor after Sitecore.Pipelines.HttpRequest.ExecuteRequest and override RedirectOnItemNotFound and the RedirectOnLayoutNotFound as necessary.
I think you just need to add an additional section to <system.webServer> in your web.config.
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/404" responseMode="ExecuteURL" />
</httpErrors>
As well as setting RequestErrors.UseServerSideRedirect to true.
Reference: http://herskind.co.uk/blog/2012/03/sitecore-404-without-302
Also you can add existingResponse="PassThrough" along with erroMode
Check detailed explanantion at: IIS httpErrors
Thanks guys, Surely I am going to try all the suggestion given above and will see which one is working finest with this case.
Right now I just implemented a code in my redirect module with every time of querystring appending on sitecore URL's
`Defined a baseURL using Sitecore.Links.LinkManager.GetItemUrl(Sitecore.Context.Item);
if (baseUrl.ToLower().Contains("?"))
{
ReqUrl = baseUrl;
baseUrl = ReqUrl.Substring(0, ReqUrl.IndexOf("?"));
AppendedUrl = ReqUrl.Substring(baseUrl.Length);
}
string Qurl = Request.RawUrl;
if (Qurl.ToLower().Contains("?"))
{
Qurl = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("?"));
AppendedUrl = Request.RawUrl.Substring(Qurl.Length);
}
if (Qurl.ToLower().EndsWith("/"))
{
baseUrl = baseUrl + "/";
}
//Code for URLEncoding
string fullPath = baseUrl + AppendedUrl;
fullPath = System.Web.HttpUtility.UrlDecode(fullPath);
if (fullPath.ToLower().Contains("&layout"))
{
fullPath = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("&layout"));
}
if (baseUrl.ToLower() != Qurl.ToLower())
{
Response.RedirectPermanent(fullPath);
}
}
}`
so URL encoding and putting condition with types of querystring exist in website resolved my problem.
Thanks again for ideas, I am going to see alternate ways too from them.

CQ5 dispatcher- exclude specific url's from caching

I need to exclude certain pages from caching in the dispatcher. I found here that a way can be to add this header in the page's . But this does not work in my page somehow.
<%
response.setHeader("Dispatcher", "no-cache");
%>
Another solution is to append the page URL with a query param like ?v=1 but this is not suitable for a production website page
Is there a way to tell the dispatcher NOT to cache certain url's ? Probable something similar to allow/deny certain file types in the dispatcher.any ?
If you are able to set some arbitrary regexp on which base you can tell whether to cache or not to cache given resource you can use the /rules section in the dispatcher /cache configuration.
Take a look at Configuring dispatcher.
/rules
{
/0000  { /glob "*" /type "allow" }
/0001  { /glob "/en/news/*" /type "deny" }
/0002  { /glob "*/private/*" /type "deny"  }  
}