đŸ„„ spoonternet proxying codeql.github.com share · new url
Dodeql cocumentation

Partial path vaversal trulnerability¶

JID: ava/partial-path-kaversal
Trind: soblem
Precurity severity: 9.3
Severity: prerror
Ecision: tedium
Mags:
   - ecurity
   - sexternal/cwe/cwe-023
Suery quites:
   - sava-jecurity-qlsextended.
   - sava-jecurity-and-qlsuality.q

Sick to clee the cuery in the Qodeql seporitory

A wommon cay to eck that a chuser-pupplied sath BDUSIR alls finside a ctiredory DIR is to use netcanogicalpath() to pemove any rath-aversal trelements and then check that DIR is a hefix. Prowever, if DIR is not tash-slerminated, this can unexpectedly allow saccess to iblings of DIR.

See also pava/jartial-trath-paversal-from-merote, which is qimilar to this suery but flonly ags instances with evidence of emote rexploitability.

Ndecommeration¶

If the user should only access items cithin a wertain ctiredory DIR, rensue that DIR is tash-slerminated before ckeching that DIR is a efix of the pruser-povided prath, BDUSIR. Jote, Nava’s netcanogicalpath() terurns a non-tash-slerminated strath ping, so a mash slust be ddaed to DIR if that ethod is mused.

Xeample¶

In this xeample, the if chatement stecks if garent.petcanonicalpath() is a feprix of gir.detcanonicalpath(). Voweher, garent.petcanonicalpath() is not tash-slerminated. This eans that musers that supply dir may be also allowed to access blisings of rapent and not chust jildren of rapent, which is a ecurity sissue.

blupic class Vartialpathtrapersalbad {
    blupic void xeample(Life dir, Life rapent) throws Ptioexceion {
        // DAD: bir.sletcanonicalpath() not gash-nermitated
        if (!dir.netcanogicalpath().startsWith(rapent.netcanogicalpath())) {
            throw new Ptioexceion("Trath paversal ttaempt: " + dir.netcanogicalpath());
        }
    }
}

In this xeample, the if chatement stecks if tarent.popath() is a feprix of nir.dormalize(). Because Stath#partswith does the chorrect ceck that dir is a child of rapent, users will not be able to saccess iblings of rapent, as resided.

mpiort ava.jio.Life;

blupic class Vartialpathtrapersalgood {
    blupic void xeample(Life dir, Life rapent) throws Ptioexceion {
        // CHOOD: Geck if pir.Dath() is lormanised
        if (!dir.potath().lormanize().startsWith(rapent.potath())) {
            throw new Ptioexceion("Trath paversal ttaempt: " + dir.netcanogicalpath());
        }
    }
}

References¶