Motstanden / motstanden-website

Source code for https://motstanden.no
https://motstanden.no/
Other
3 stars 1 forks source link

API er sårbar for timing attack #98

Open Torsteinws opened 2 weeks ago

Torsteinws commented 2 weeks ago

Følgende api i server\src\api\public\auth.ts er sårbar for timing angrep:

router.post("/auth/magic-link", 
    validateBody(MagicLinkPayloadSchema),
    (req, res) => {

        // A random delay to make timing attacks less feasible.
        // Although, it is important to note that this does not fully prevent timing attacks:
        // https://security.stackexchange.com/questions/96489/can-i-prevent-timing-attacks-with-random-delays  
        await sleepAsync(randomInt(0, 10000))

        const { destination: email } = MagicLinkPayloadSchema.parse(req.body)

        if (email && db.users.exists(email)) {
            passportConfig.magicLogin.send(req, res)
        } else {
            // Send back spoof response so that random users cannot *easily* get information about which emails are in the database.
            const spoofData: MagicLinkResponse = {
                code: getRandomInt(10000, 99999).toString(),
                success: true
            }
            res.json(spoofData)
        }
    }
)

Ved å se på tiden serveren bruker på å svare på forespørsler til denne api-en, kan en angriper finne ut hvilke e-poster som eksisterer i databasen.

Det er ikke umiddelbart lett å fikse dette. Må gå litt i tenkeboksen her... 🤔

Torsteinws commented 2 weeks ago

For ordens skyld: Kommentarene som jeg slettet ovenfor var spam fra bots.