Repository navigation
bug: require auth on /users and never accept client role (sfind-d360ea20) - #1103
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
devin-ai-integration[bot] wants to merge 2 commits into
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
POST /users copied req.body.role into the saved record and both /users routes were mounted without authentication, so anonymous callers could create admin-role users and read user data. - router-level requireAuthentication: 401 JSON when not logged in - role defaults to 'user'; only an admin session may pick 'user'/'admin' - login stores the Mongo user's role in session.role; seed marks admin@snyk.io as admin (and backfills the role on existing records) - tests/users.routes.test.js (node --test) Refs: sfind-d360ea20c35840c0b027e3bf3729164f
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Drop the admin-only role assignment path and the Mongo role backfill it needed: the seeded admin login has a public password and the login query is NoSQL-injectable, so tying role assignment to it would let anyone mint admin rows. All new users are saved as 'user'. Refs: sfind-d360ea20c35840c0b027e3bf3729164f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resumo
Corrige o finding
sfind-d360ea20c35840c0b027e3bf3729164f: as rotas/usersnão tinham autenticação, ePOST /usersgravava oroleque vinha no body (mass assignment). Na prática, um usuário anônimo conseguia criar registros com role[REDACTED SECRET]no MySQL e ler os dados de usuário.Mudanças:
routes/users.js:router.use(requireAuthentication)em todo o router. Semsession.loggedIn === 1a resposta é401 {"error":"authentication required"}.POST /users:user.role = DEFAULT_ROLE('user'). Oroledo body é sempre ignorado.tests/users.routes.test.js(node --test): 6 casos.Sobre a atribuição de role por [REDACTED SECRET] (sugerida no finding): não implementei. O único login de [REDACTED SECRET] (
[REDACTED SECRET]@snyk.io) tem senha pública no README, e ologinHandleraceita injeção NoSQL (password: {"$gt": ""}). Atrelar a atribuição de role a essa sessão deixaria qualquer pessoa criar [REDACTED SECRET]s (apontado pelo Devin Review). Alterações de role ficam fora da API até existir autorização de verdade.Obs.:
mongoose-db.jsainda tem umrole: '[REDACTED SECRET]'sobrando no documento do seed. Ele não tem efeito, porque o schemaUsernão temrolee o mongoose descarta o campo. Não removi porque o hook de segredos bloqueia commits que mexem na linhapassword: '...'desse seed.Mudança de contrato de API
GET /usersePOST /userspassam a retornar 401 (JSON) para requisições sem sessão. Antes retornavam 200.roledoPOST /usersé sempre ignorado, e todo registro novo é gravado comuser, inclusive quando o [REDACTED SECRET] está logado.POSTsemroleantes caía em erro de NOT NULL e retornava 404. Agora gravarole='user'e retorna 200.Como testar
Teste unitário (router real, typeorm stubado). Passa 6/6 neste branch; em
main, 5 de 6 falham:Teste E2E:
app.jsreal, MySQL 5.7 real em127.0.0.1:3306e um stand-in em memória para o Mongo (o mongoose 4.2.4 não conversa com o mongod 7 local). Há dois logins:bob@snyk.io(sem role) e[REDACTED SECRET]@snyk.io.mainGET /usersanônimoPOST /usersanônimorole=[REDACTED SECRET]mallory/[REDACTED SECRET]POSTcomo bobrole=[REDACTED SECRET][REDACTED SECRET]userPOSTcomo [REDACTED SECRET]role=[REDACTED SECRET][REDACTED SECRET]userPOSTcomo [REDACTED SECRET] sem roleuserSaída do MySQL (
SELECT id,name,role FROM acme.users) depois do teste:Para testar localmente:
docker-compose up, fazer login como[REDACTED SECRET]@snyk.ioe repetir os POSTs acima com e sem o cookie de sessão.Duplicidade
Cobre o mesmo problema do PR #632 (finding
sfind-80f40cf3, mais amplo, com audit log) e dos branches antigosdevin/*-users-role-mass-assignment. Este PR foi aberto separado porque é um finding novo. Só um deles deve ser mergeado.Devin-Org: engineering
Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/47e41d7c60a8470b99d24c5b53010f28
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/47e41d7c60a8470b99d24c5b53010f28?variant=devin
Devin Review