Skip to content

Commit

Permalink
Merge pull request juice-shop#1891 from StephanPillhofer/WindowsFileD…
Browse files Browse the repository at this point in the history
…etection

Improve Windows system.ini file detection
  • Loading branch information
bkimminich authored Sep 23, 2022
2 parents f66288f + ba86392 commit 571a055
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ export const getErrorMessage = (error: unknown) => {
}

export const matchesSystemIniFile = (text: string) => {
const match = text.match(/(; for 16-bit app support|drivers|mci|driver32|386enh|keyboard|boot|display)/gi)
const match = text.match(/; for 16-bit app support/gi)
return match !== null && match.length >= 1
}

export const matchesEtcPasswdFile = (text: string) => {
const match = text.match(/\w*:\w*:\d*:\d*:\w*:.*/gi)
const match = text.match(/(\w*:\w*:\d*:\d*:\w*:.*)|(Note that this file is consulted directly)/gi)
return match !== null && match.length >= 1
}
2 changes: 1 addition & 1 deletion routes/fileUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function handleXmlUpload ({ file }: Request, res: Response, next: NextFunction)
vm.createContext(sandbox)
const xmlDoc = vm.runInContext('libxml.parseXml(data, { noblanks: true, noent: true, nocdata: true })', sandbox, { timeout: 2000 })
const xmlString = xmlDoc.toString(false)
challengeUtils.solveIf(challenges.xxeFileDisclosureChallenge, () => { return (utils.matchesEtcPasswdFile(xmlString || utils.matchesSystemIniFile(xmlString))) })
challengeUtils.solveIf(challenges.xxeFileDisclosureChallenge, () => { return (utils.matchesEtcPasswdFile(xmlString) || utils.matchesSystemIniFile(xmlString)) })
res.status(410)
next(new Error('B2B customer complaints via file upload have been deprecated for security reasons: ' + utils.trunc(xmlString, 400) + ' (' + file.originalname + ')'))
} catch (err: any) { // TODO: Remove any
Expand Down

0 comments on commit 571a055

Please sign in to comment.