Skip to content

Commit

Permalink
Fix unvalidated redirects (#3252)
Browse files Browse the repository at this point in the history
  • Loading branch information
uurien authored and tlhunter committed Jun 23, 2023
1 parent 1ec168f commit e15366b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class UnvalidatedRedirectAnalyzer extends InjectionAnalyzer {
if (!value) return false

const ranges = getRanges(iastContext, value)
return !this._isRefererHeader(ranges)
return ranges && ranges.length > 0 && !this._isRefererHeader(ranges)
}

_isRefererHeader (ranges) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ describe('Unvalidated Redirect vulnerability', () => {
const location = newTaintedString(iastCtx, 'http://user@app.com/', 'pathParam', 'Request')
res.header('X-test', location)
}, UNVALIDATED_REDIRECT)

testThatRequestHasNoVulnerability((req, res) => {
redirectFunctions.insecureWithResHeaderMethod('location', 'http://user@app.com/', res)
}, UNVALIDATED_REDIRECT)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('unvalidated-redirect-analyzer', () => {
},

getRanges: (iastContext, value) => {
if (value === NOT_TAINTED_LOCATION) return []
if (value === NOT_TAINTED_LOCATION) return null

if (value === TAINTED_HEADER_REFERER_ONLY) {
return [REFERER_RANGE]
Expand All @@ -52,6 +52,7 @@ describe('unvalidated-redirect-analyzer', () => {

let report
beforeEach(() => {
sinon.stub(overheadController, 'hasQuota').returns(1)
report = sinon.stub(unvalidatedRedirectAnalyzer, '_report')
})

Expand Down Expand Up @@ -91,24 +92,18 @@ describe('unvalidated-redirect-analyzer', () => {
})

it('should report Location header with tainted string value', () => {
sinon.stub(overheadController, 'hasQuota').returns(1)

unvalidatedRedirectAnalyzer.analyze('Location', TAINTED_LOCATION)

expect(report).to.be.called
})

it('should not report if tainted origin is referer header exclusively', () => {
sinon.stub(overheadController, 'hasQuota').returns(1)

unvalidatedRedirectAnalyzer.analyze('Location', TAINTED_HEADER_REFERER_ONLY)

expect(report).to.not.be.called
})

it('should report if tainted origin contains referer header among others', () => {
sinon.stub(overheadController, 'hasQuota').returns(1)

unvalidatedRedirectAnalyzer.analyze('Location', TAINTED_HEADER_REFERER_AMONG_OTHERS)

expect(report).to.be.called
Expand Down

0 comments on commit e15366b

Please sign in to comment.