Skip to content

Commit

Permalink
Merge pull request #205 from sematext/token_blacklist_status_code_con…
Browse files Browse the repository at this point in the history
…figurable

Make HTTP status for blacklisted tokens configurable
  • Loading branch information
megastef authored Feb 28, 2020
2 parents b7f7525 + fd0f480 commit 2642074
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/plugins/input/cloudfoundry.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ InputCloudFoundry.prototype.cloudFoundryHandler = function (req, res) {
}

if ((self.config.useIndexFromUrlPath === true && !token) || self.tokenBlackList.isTokenInvalid(token)) {
res.statusCode = 404
res.statusCode = self.config.invalidTokenStatus || 403
res.end(`invalid logs token in url ${req.url}\n`)
return
}
Expand Down
5 changes: 3 additions & 2 deletions lib/plugins/input/heroku.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,15 @@ InputHeroku.prototype.herokuHandler = function (req, res) {
}
}

if (!token) {
if (self.config.useIndexFromUrlPath && !token) {
res.statusCode = 404
res.end('<html><head><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"</head><body><div class="alert alert-danger" role="alert">Error: Missing Logsene Token ' +
req.url + '. Please use /LOGSENE_TOKEN. More info: <ul><li><a href="https://github.com/sematext/logagent-js#logagent-as-heroku-log-drain">Heroku Log Drain for Logsene</a> </li><li><a href="https://www.sematext.com/logsene/">Logsene Log Management by Sematext</a></li></ul></div></body><html>')
return
}

if ((self.config.useIndexFromUrlPath === true && !token) || self.tokenBlackList.isTokenInvalid(token)) {
res.statusCode = 404
res.statusCode = self.config.invalidTokenStatus || 403
res.end(`invalid logs token in url ${req.url}\n`)
return
}
Expand Down
5 changes: 3 additions & 2 deletions lib/plugins/input/journald-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Parser {
getLog () {
return this.log
}

// lines from http stream are pushed here
consume (data) {
// make sure that multiLine status ends with a new __CURSOR line
Expand Down Expand Up @@ -245,8 +246,8 @@ JournaldUpload.prototype.journaldHttpHandler = function (req, res) {
}

if ((self.config.useIndexFromUrlPath === true && !token) || self.tokenBlackList.isTokenInvalid(token)) {
res.statusCode = 401
res.end(`invalid logs token in url ${req.url}`)
res.statusCode = self.config.invalidTokenStatus || 403
res.end(`invalid logs token in url ${req.url}\n`)
return
}

Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/input/kubernetesAudit.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ KubernetesAudit.prototype.HttpHandler = function (req, res) {
}
}
if ((self.config.useIndexFromUrlPath === true && !token) || self.tokenBlackList.isTokenInvalid(token)) {
res.statusCode = 401
res.statusCode = self.config.invalidTokenStatus || 403
res.end(`invalid logs token in url ${req.url}`)
return
}
Expand Down

0 comments on commit 2642074

Please sign in to comment.