Skip to content

Commit

Permalink
Reject URLs where the path starts with triple slash (#54057)
Browse files Browse the repository at this point in the history
  • Loading branch information
heiskr authored Jan 22, 2025
1 parent 13f99a6 commit b8b8ff7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/shielding/middleware/handle-invalid-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ExtendedRequest } from '@/types'
// one of these.
// These are clearly intentional "guesses" made by some sort of
// pen-testing bot.
const JUNK_STARTS = ['///']
const JUNK_ENDS = [
'/package.json',
'/package-lock.json',
Expand Down Expand Up @@ -37,6 +38,12 @@ const JUNK_BASENAMES = new Set([
function isJunkPath(path: string) {
if (JUNK_PATHS.has(path)) return true

for (const junkPath of JUNK_STARTS) {
if (path.startsWith(junkPath)) {
return true
}
}

for (const junkPath of JUNK_ENDS) {
if (path.endsWith(junkPath)) {
return true
Expand Down

0 comments on commit b8b8ff7

Please sign in to comment.