Reject tags owned by another business in charge tag updates

Aperta
#4,920 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
69/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Start with validateUploadTarget in packages/server/src/modules/documents/helpers/upload-to-charge.helper.ts and its tests, then trace the listed charge and tag mutation paths to ChargeTagsProvider.insertChargeTag. Validate every caller-supplied tag id against the write-target business before any batch writes. Done means each listed mutation rejects a visible tag owned by another business with an error naming its id, with unit tests covering each path.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

Writes that link a tag to a charge accept any tag id the caller can read, without checking that the tag belongs to the business being written to.

Under the multi-business RLS scope (2026-05-25T10-00-00.rls-multi-business-scope.ts):

  • Reads on tags are owner_id = ANY(get_current_business_scope()), so a request can see the tags of every business in its scope.
  • Writes on charge_tags are pinned to the single write-target business (get_current_business_id()).
  • charge_tags.tag_id is a bare foreign key, so it accepts any existing tag id.

As a result, a caller whose read scope covers businesses A and B can write a charge of A to point at a tag owned by B. That is cross-tenant data mixing.

The new-charge upload path already guards against this. #4904 added an ownership check in validateUploadTarget (packages/server/src/modules/documents/helpers/upload-to-charge.helper.ts), which rejects tags whose owner_id differs from AdminContextProvider.getVerifiedAdminContext().ownerId. The older tag-write paths don't have it.

Affected call sites (caller-supplied tag ids → ChargeTagsProvider.insertChargeTag)

  • packages/server/src/modules/charges/resolvers/charges.resolver.ts:
    • updateCharge: the tag diff, around the insertChargeTag call.
    • batchUpdateCharges: via batchUpdateChargesTags in charges/helpers/batch-update-charges.ts.
  • packages/server/src/modules/tags/resolvers/tags.resolvers.ts: the batchUpdateChargesTags mutation, via applyChargeTagChanges in tags/helpers/batch-charge-tags.helper.ts. The MCP tool accounter_update_charges_tags goes through this path too.

Not affected: business-trips-expenses.helper.ts and financial-charge.helper.ts also call insertChargeTag, but with server-chosen tags.

Suggested fix

  • Extract the check from validateUploadTarget into a shared helper in the tags module, e.g. assertTagsOwnedByWriteTarget(injector, tagIds). It would load the tags with TagsProvider.getTagByIDLoader, reject missing ids, and reject tags whose owner_id differs from the write-target owner.
  • Call it at each site above before any write. The batch paths should validate the whole id list up front, so a bad id can't leave a partial update behind.
  • Consider moving this into ChargeTagsProvider.insertChargeTag itself, so a future caller can't skip it.

Done when

  • Each mutation above rejects a tag visible through the read scope but owned by another business, with a clear error naming the id.
  • Unit tests cover each path, including a "visible tag owned by another business" case, mirroring the tests in upload-to-charge.helper.test.ts.
  • Optionally, a DB-backed integration test with two businesses in scope.
Lingua principale
TypeScript
Stelle
30
Fork
10
Merge medio
2g 12h
PR unite (30g)
276

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Urigo/accounter-fullstack

Tutte le issue di Urigo/accounter-fullstack

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.