跳到正文
DEV Community· Ramatech Innovations·· 5 小時前AI 評分59

RAG 答案即使正確,仍可能洩漏資料

Your RAG Answer Can Be Correct—and Still Leak Data

AI 導讀

RAG 助手即使提供正確答案和引用,若未先按用戶權限限制可檢索內容,仍可能讓未獲授權的資料進入模型並造成外洩。文章建議由可信的身份驗證系統取得用戶權限,在建立生成上下文前完成授權檢查,並將權限套用於關鍵字搜尋、向量搜尋及後備查詢。還需處理權限更新、快取答案和缺失或過時的權限資訊,並測試跨用戶或租戶存取、權限撤銷等拒絕情境;檢查範圍應包括檢索內容及引用,而不只是最終回答。

正文

A RAG assistant answers a question accurately and includes the right citation.

There is still a critical question to ask:

Was this user allowed to read that source?

Imagine an internal assistant searching engineering runbooks, customer contracts, and HR documents. All three may contain relevant information. They do not necessarily share the same audience.

Retrieval relevance and access permission are separate decisions.

The failure starts before generation

Consider this pipeline:

User question
    → Search the entire document collection
    → Send matching chunks to the model
    → Ask the model to hide restricted information

The restricted content has already reached the model. A prompt instruction cannot replace an authorization check.

The application should establish which content the user may access before constructing the generation context.

Microsoft's document-level access control documentation describes approaches for restricting search results using document permissions and security filters. The exact implementation depends on the data source and search platform.

Carry permissions into the retrieval layer

When a document is split into chunks, its access rules must remain enforceable.

For example, a chunk might carry metadata such as:

{
  "chunk_id": "runbook-42-chunk-3",
  "document_id": "runbook-42",
  "tenant_id": "tenant-a",
  "allowed_groups": ["platform-operations"],
  "permission_version": 7
}

This is illustrative metadata, not a complete authorization implementation.

The backend must derive the requesting user's identity and permissions from a trusted authentication system. Accepting an arbitrary tenant ID or group list from the browser would undermine the control.

A useful flow is:

Authenticate user
    → Resolve tenant and access permissions
    → Retrieve within the authorized scope
    → Build context from authorized chunks
    → Generate answer
    → Return permitted citations

The authorization rule must apply across every retrieval path, including keyword search, vector search, and fallback queries.

Permission changes are data changes

A document can remain unchanged while its permissions change.

Someone moves teams. A customer contract becomes restricted. A user loses access to a workspace.

If the retrieval index still contains yesterday's permissions, today's answer may expose information the user can no longer read.

Define how permission updates reach the index, how quickly revocations take effect, and what happens when permission information is missing or stale.

The same question applies to cached answers: can a response generated for one user be returned to another? Cache reuse must respect the requesting user's current access rights.

Test the denial paths

A useful evaluation set includes more than questions the assistant should answer.

Check these cases too:

  • Two users ask the same question but have different document access.
  • Two tenants have documents with similar titles.
  • A user's access is revoked after an answer is cached.
  • A chunk has missing permission metadata.
  • No authorized source supports the requested answer.

Inspect retrieved chunks and citations as well as the final response. A polite refusal does not prove that restricted content stayed out of the pipeline.

Make access boundaries part of answer quality

A production RAG evaluation should ask:

  1. Did retrieval find useful evidence?
  2. Did the answer accurately represent that evidence?
  3. Was every included source authorized for this user?

Getting the first two right is not enough.

How are you testing permission changes and cross-tenant retrieval in your RAG applications?

來源:DEV Community · dev.to