Skip to content

Commit

Permalink
stop gap for open redirect (github#22839)
Browse files Browse the repository at this point in the history
  • Loading branch information
rachmari authored Nov 16, 2021
1 parent 1b74f30 commit 4cab1e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const hasLiquid = /[{{][{%]/
export const dataReference = /{% ?data\s(?:early-access\.)?(?:reusables|variables|ui)\..*?%}/gm
export const imagePath = /\/?assets\/images\/.*?\.(png|svg|gif|pdf|ico|jpg|jpeg)/gi
export const homepagePath = /^\/\w{2}$/ // /en, /ja /cn
export const multipleSlashes = /^\/{2,}/
export const multipleSlashes = /^(\/|\\){2,}/
export const assetPaths = /\/(?:javascripts|stylesheets|assets|node_modules|dist|_next)\//
export const oldApiPath = /\/v[34]\/(?!guides|overview).+?\/.+/
export const staticRedirect = /<link rel="canonical" href="(.+?)">/
Expand Down
15 changes: 15 additions & 0 deletions tests/routing/middleware/redirects/help-to-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,19 @@ describe('help.github.com redirect middleware', () => {
`<p>Moved Permanently. Redirecting to <a href="${expectedRedirect}">${expectedRedirect}</a></p>`
)
})

it('only redirects to a docs.github.com path backlash edition', async () => {
const req = {
hostname: 'help.github.com',
protocol: 'https',
originalUrl: '/\\evil.com',
}
const res = new MockExpressResponse()
const next = jest.fn()
await middleware(req, res, next)
const expectedRedirect = 'https://docs.github.com/evil.com'
expect(res._getString()).toEqual(
`<p>Moved Permanently. Redirecting to <a href="${expectedRedirect}">${expectedRedirect}</a></p>`
)
})
})

0 comments on commit 4cab1e7

Please sign in to comment.