Merge pull request #699 from lbryio/fixFailedLogClamp

Fix failed referrer clamp in logMetrics
This commit is contained in:
Shawn K 2018-11-09 10:57:30 -05:00 committed by GitHub
commit e6400542e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,8 +10,14 @@ function logMetricsMiddleware(req, res, next) {
let referrer = req.get('referrer');
if(referrer && referrer.length > 255) {
// Attempt to "safely" clamp long URLs
referrer = /(.*?)#.*/.exec(referrer)[1];
try {
// Attempt to "safely" clamp long URLs
referrer = /(.*?)#.*/.exec(referrer)[1];
} catch(e) {
// Cheap forced string conversion & clamp
referrer = new String(referrer);
referrer = referrer.substr(0, 255);
}
if(referrer.length > 255) {
logger.warn('Request refferer exceeds 255 characters:', referrer);