AI trong code · M3 · quy trình teamAI in code · M3 · team process

Biến rủi ro AI thành quy trình của teamTurning AI risk into team process

M2 là bảng kê của riêng bạn. M3 biến nó thành luật chung có ba lớp: văn bản, máy, dấu vết. Việc gì máy kiểm được thì đừng để văn bản gánh. M2 was your own inventory. M3 turns it into shared rules in three layers: paper, machine, trace. If a machine can check it, don't make a document carry it.

M3 – DONE Team lead duyệt policy và team áp dụng ít nhất 1 sprint. The team lead approves the policy and the team applies it for at least 1 sprint.
Prompt → commit → push → PR → merge, with the three layers: policy before the prompt, machine gates at commit, push and CI, and the PR template at review. ① POLICY ② PIPELINE · gitleaks · deps-check ③ PR TEMPLATE Prompt Commit Push PR Merge pre-commit push protection CI + reviewCI + review .env pkg? code có testtested code secret → chặn ở commitsecret → blocked at commit package lạ → giữ ở CIunknown package → held in CI
01

Từ "tôi cẩn thận" sang "team an toàn mặc định"From "I'm careful" to "safe by default"

Rủi ro nằm ở người kém cẩn thận nhất vào ngày bận nhất: dán .env vào ChatGPT cá nhân, thêm package AI gợi ý mới xuất hiện trên npm 3 ngày, duyệt 400 dòng code AI sinh mà không có test. Những việc này không cần thêm kiến thức. Chúng cần quy trình. Risk lives with the least careful person on their busiest day: pasting .env into personal ChatGPT, adding an AI-suggested package that appeared on npm 3 days ago, approving 400 lines of untested AI code. None of these needs more knowledge. They need process.

Lớp 1Layer 1

Văn bảnPaper

AI usage policy 1–2 trang.A 1–2 page AI usage policy.

Bắt đượcCatchesHành vi ngoài code: dán dữ liệu vào chat, dùng tài khoản cá nhân.Behaviour outside code: pasting data into chat, personal accounts.
Không bắt đượcMissesKhông tự chạy; phụ thuộc trí nhớ người đọc.Doesn't run itself; depends on memory.
Lớp 2Layer 2

MáyMachine

Secret scanning + kiểm tra dependency trong pipeline.Secret scanning + dependency checks in the pipeline.

Bắt đượcCatchesSecret trong commit, package có lỗ hổng, package lạ hoặc quá mới.Secrets in commits, vulnerable packages, unknown or brand-new packages.
Không bắt đượcMissesDữ liệu đã dán vào prompt (không đi qua git).Data pasted into a prompt (never goes through git).
Lớp 3Layer 3

Dấu vếtTrace

Mục AI-assisted trong PR template.An AI-assisted section in the PR template.

Bắt đượcCatchesCho reviewer biết phần nào AI viết và đã kiểm thế nào.Tells the reviewer which part AI wrote and how it was checked.
Không bắt đượcMissesNgười khai sai hoặc khai thiếu.Wrong or incomplete declarations.

Ba lớp bù lỗ cho nhau. Thiếu lớp nào, rủi ro lọt qua đúng chỗ đó.The layers cover each other's holes. Drop one and risk slips through exactly there.

02

Ví dụ: cửa hàng online 5 dev, sau M2Example: a 5-dev online shop, after M2

Repo shop-web (Next.js) và shop-api (Node), triển khai bằng GitHub Actions. Team lead muốn: một văn bản ngắn để mọi người ký nhận, CI chặn lỗi phổ biến nhất, và cách để reviewer biết PR nào có code AI sinh. Repos shop-web (Next.js) and shop-api (Node), deployed with GitHub Actions. The team lead wants a short document everyone signs off on, CI that blocks the common mistakes, and a way for reviewers to know which PRs contain AI code.

Copilot BusinessTài khoản tổ chức, đã tắt gợi ý trùng code công khaiOrg account, public-code matching off
Claude Code (Team)Tài khoản tổ chức, permissions.deny cho .env*Org account, permissions.deny on .env*
ChatGPT cá nhân ×2Personal ChatGPT ×2Rủi ro cao: có thể bị dùng để huấn luyệnHigh risk: may be used for training
Cursor1 bạn dùng, đang bật Privacy Mode1 dev, Privacy Mode on
2 MCP server2 MCP serversPostgres read-only, Jira; chưa có danh sách duyệtPostgres read-only, Jira; no approved list yet
03

AI usage policy 1–2 trangA 1–2 page AI usage policy

Policy 10 trang thì không ai đọc. 1–2 trang đọc trong 5 phút và nhớ được phần chính. Chi tiết (pattern secret, cấu hình CI) để ở file cấu hình. Một policy tốt trả lời đủ 7 câu hỏi: Nobody reads a 10-page policy. 1–2 pages take 5 minutes and stick. Details (secret patterns, CI config) live in config files. A good policy answers 7 questions:

1Phạm viScopeAi, repo nào, công cụ nào?Who, which repos, tools?
2Công cụToolsDùng gì, tài khoản nào?What, which account?
3Dữ liệu cấmBanned dataCái gì không được dán?What never gets pasted?
4ReviewReviewĐiều kiện merge code AI?Conditions to merge AI code?
5Khai báoDisclosureGhi ở đâu là có dùng AI?Where to record AI use?
6Sự cốIncidentsLỡ lộ secret thì làm gì?Leaked a secret — now what?
7Ngoại lệExceptionsAi duyệt, khi nào xem lại?Who approves, when reviewed?

Công cụ: ba mức, không phải có/khôngTools: three tiers, not yes/no

Được duyệtApproved

Dùng cho mọi loại code, trừ dữ liệu cấm.Any code, except banned data.

Copilot Business, Claude Code (Team)
Có điều kiệnConditional

Chỉ cho việc không chạm code/dữ liệu công ty, hoặc khi đã bật setting bắt buộc.Only for work off company code/data, or with a required setting on.

Cursor + Privacy Mode; ChatGPT cá nhân chỉ hỏi kiến thức chungCursor + Privacy Mode; personal ChatGPT for general knowledge only
Không được dùngNot allowed

Không đạt tiêu chí tối thiểu.Fails the minimum bar.

Extension AI không rõ nguồn; MCP server chưa reviewAI extensions of unknown origin; unreviewed MCP servers
01Gói doanh nghiệp, quản lý tài khoản tập trungBusiness plan, central account management
02Mặc định không huấn luyện trên dữ liệu, hoặc tắt được ở cấp tổ chứcNo training on your data by default, or off at org level
03Thời gian lưu dữ liệu rõ ràng, có văn bảnClear, documented retention
04Rút quyền được khi nhân viên nghỉAccess revocable when someone leaves

Danh sách chỉ có "được" và "không được" sẽ đẩy người ta sang dùng chui. Bốn tiêu chí trên lấy thẳng từ cột "chính sách lưu dữ liệu" của bảng kê M2. MCP server cũng là một công cụ: ghi rõ nó đọc gì, ghi gì, ai đã duyệt.A bare allowed/not-allowed list pushes people into shadow use. The four criteria come straight from the "retention policy" column of the M2 inventory. An MCP server is a tool too: note what it reads, writes, and who reviewed it.

Dữ liệu cấm đưa vào prompt: đèn giao thôngData banned from prompts: a traffic light

MàuColourLoạiKindVí dụExamplesQuy tắcRule
CấmBannedSecretAPI key, token, mật khẩu DB, private key, nội dung .env, connection stringAPI keys, tokens, DB passwords, private keys, .env contents, connection stringsKhông bao giờ, kể cả công cụ được duyệtNever, even with approved tools
CấmBannedPII khách hàng (thông tin định danh cá nhân)Customer PII (personally identifiable information)Tên + SĐT + địa chỉ giao hàng, email, đơn hàng thật, dump bảng customersName + phone + delivery address, email, real orders, a customers dumpKhông bao giờ. Cần dữ liệu mẫu thì dùng fakerNever. Need sample data? Use faker
CấmBannedMã nguồn mậtConfidential sourceThuật toán định giá, cấu hình chống gian lận, code đối tác theo NDAPricing algorithm, anti-fraud config, partner code under NDAKhông công cụ nào, trừ khi team lead đồng ý bằng văn bảnNo tool, unless the team lead agrees in writing
Cẩn thậnCarefulCode thường của công tyOrdinary company codeComponent UI, API CRUD, testUI components, CRUD APIs, testsChỉ công cụ được duyệtApproved tools only
Tự doFreeKiến thức chungGeneral knowledge"useEffect cleanup chạy khi nào?", code mẫu từ docs công khai"When does a useEffect cleanup run?", sample code from public docsCông cụ nào cũng đượcAny tool
Mẹo: trước khi dán, hỏi "nếu đoạn này lên báo thì sao?". Nếu câu trả lời là "phải xoay vòng key" hoặc "phải báo khách hàng" thì đó là màu đỏ.Trick: before pasting, ask "what if this ended up in the news?" If the answer is "we'd rotate keys" or "we'd notify customers", it's red.

Bốn quy tắc review code AI sinhFour review rules for AI-generated code

máy kiểmmachine

1 · Bắt buộc có test1 · Tests are mandatory

Test chạy trong CI và thất bại khi bỏ code mới. AI viết code "trông đúng" rất giỏi; test là cách rẻ nhất để biết nó đúng thật.Tests run in CI and fail without the new code. AI is great at code that "looks right"; tests are the cheapest proof it is.

máy kiểmmachine

2 · Dependency mới phải được kiểm2 · New dependencies get checked

Tồn tại trên registry, không quá mới, có người duy trì, license cho phép. Chống slopsquatting (M2: ~20% package AI gợi ý không tồn tại).Exists on the registry, not too new, maintained, allowed licence. Guards against slopsquatting (M2: ~20% of AI-suggested packages don't exist).

người + PR templatehuman + PR template

3 · Giải thích được từng dòng3 · Explain every line

Không giải thích được thì không merge. AI là công cụ; người mở PR vẫn là người chịu trách nhiệm.Can't explain it, don't merge it. AI is a tool; the PR author stays accountable.

người + CODEOWNERShuman + CODEOWNERS

4 · Vùng nhạy cảm: 2 reviewer4 · Sensitive areas: 2 reviewers

Auth, thanh toán, phân quyền, xử lý PII: thêm một reviewer, ghi trong CODEOWNERS.Auth, payments, permissions, PII handling: one extra reviewer, set in CODEOWNERS.

Mục 6 · sự cốSection 6 · incidents Lỡ dán secret vào AI hoặc lỡ commit secret: coi như đã lộ. Trong 1 giờ: thu hồi và tạo key mới, báo team lead, ghi lại sự cố. Không chỉ xoá commit: secret đã nằm trong lịch sử git, bản fork và log của công cụ AI. Không đổ lỗi, để người ta báo sớm thay vì giấu. Pasted a secret into AI, or committed one: treat it as leaked. Within 1 hour: revoke and issue a new key, tell the team lead, log the incident. Don't just delete the commit: the secret is already in git history, forks and the AI tool's logs. No blame, so people report early instead of hiding it.
03b

Soạn policy của team bạnBuild your team's policy

Chọn công cụ, dữ liệu cấm và quy tắc review. Bên phải là policy đầy đủ 7 mục và PR template tương ứng. Thước đo cho biết policy còn nằm trong 1–2 trang không. Mọi thay đổi lưu trong trình duyệt của bạn. Pick tools, banned data and review rules. On the right: the full 7-section policy and the matching PR template. The meter shows whether it still fits in 1–2 pages. Everything is saved in your browser.

Phạm viScope

Công cụ · bấm để đổi mứcTools · click to change tier

Dữ liệu cấmBanned data

Quy tắc reviewReview rules

Sự cố & cập nhậtIncidents & updates

Độ dàiLength
04

Đưa vào pipeline: secret + dependencyInto the pipeline: secrets + dependencies

Secret scanning có bốn tầng. Chặn càng sớm càng rẻ, nhưng chỉ tầng CI là không ai bỏ qua được.Secret scanning has four tiers. The earlier the cheaper, but only the CI tier can't be skipped.

① máy devdev machine

pre-commit gitleaks

gitleaks git --staged. Rẻ nhất vì secret chưa rời máy, nhưng dev tắt hook được.gitleaks git --staged. Cheapest, the secret hasn't left the machine, but hooks can be disabled.

nên cóshould
② push

push protection

GitHub: miễn phí cho repo public; repo private của tổ chức cần gói trả phí (Secret Protection). Kiểm tra lại giá.GitHub: free for public repos; org private repos need a paid plan (Secret Protection). Check current pricing.

tuỳ góiplan-dependent
③ PR / CI

gitleaks trên diffgitleaks on the diff

Lưới an toàn: ai tắt hook thì CI vẫn chặn. Đặt là required check (bắt buộc qua mới được merge).The safety net: hook off, CI still blocks. Make it a required check.

bắt buộcmust
④ khi mới bậton switch-on

quét toàn bộ lịch sửfull-history scan

Secret cũ đã nằm trong lịch sử git, quét diff không thấy. Chạy 1 lần rồi định kỳ.Old secrets sit in git history where a diff scan can't see them. Run once, then on a schedule.

1 lầnonce

gitleaks-action cần GITLEAKS_LICENSE cho repo của tổ chức, và bản v2 đã ngừng chạy. Chạy thẳng binary gitleaks (MIT) thì đơn giản hơn. Cảnh báo nhầm (false positive) là thứ giết chết secret scanning: đưa file test và key mẫu vào allowlist (danh sách bỏ qua) trong .gitleaks.toml, mỗi dòng ghi lý do.gitleaks-action needs a GITLEAKS_LICENSE for org repos, and v2 has stopped running. Running the gitleaks binary (MIT) directly is simpler. False positives kill secret scanning: allowlist test files and sample keys in .gitleaks.toml, each line with a reason.

Package có lỗ hổng đã biết không?Does the package have known vulnerabilities?

Bắt CVE trong dependency trực tiếp và gián tiếp.Catches CVEs in direct and transitive dependencies.

osv-scanner · npm audit · Dependabot

Package mới này có đáng tin không?Should we trust this new package?

Rủi ro đặc thù của code AI sinh. Package độc hại đăng hôm qua chưa có CVE, nên npm audit báo sạch. Phải hỏi registry: tồn tại? tuổi? lượt tải? license?The risk specific to AI code. A malicious package published yesterday has no CVE, so npm audit is clean. Ask the registry: exists? age? downloads? licence?

check-new-deps.mjs · Socket · dependency-review-action (private repo: gói trả phí)(private repos: paid plan)
scripts/check-new-deps.mjs · ~30 dònglines
import { execSync } from 'node:child_process';
const base = process.argv[2] ?? 'origin/main';
const MIN_AGE_DAYS = 30, MIN_WEEKLY = 1000;
const LICENSES = new Set(['MIT', 'ISC', 'Apache-2.0', 'BSD-2-Clause', 'BSD-3-Clause']);

const deps = (pkg) => ({ ...pkg.dependencies, ...pkg.devDependencies });
const before = deps(JSON.parse(execSync(`git show ${base}:package.json`, { encoding: 'utf8' })));
const after = deps(JSON.parse(execSync('cat package.json', { encoding: 'utf8' })));
const added = Object.keys(after).filter((n) => !(n in before));

let fail = 0;
for (const name of added) {
  const meta = await fetch(`https://registry.npmjs.org/${name}`);
  if (meta.status === 404) { console.error(`✗ ${name}: not on npm`); fail++; continue; }
  const m = await meta.json();
  const ageDays = (Date.now() - new Date(m.time.created)) / 864e5;
  const dl = await (await fetch(`https://api.npmjs.org/downloads/point/last-week/${name}`)).json();
  const lic = m.license ?? m.versions?.[m['dist-tags'].latest]?.license;
  const problems = [];
  if (ageDays < MIN_AGE_DAYS) problems.push(`${ageDays.toFixed(0)} days old`);
  if ((dl.downloads ?? 0) < MIN_WEEKLY) problems.push(`${dl.downloads ?? 0} downloads/week`);
  if (!LICENSES.has(lic)) problems.push(`licence ${lic}`);
  if (problems.length) { console.error(`✗ ${name}: ${problems.join(', ')}`); fail++; }
  else console.log(`✓ ${name}`);
}
process.exit(fail ? 1 : 0);
.github/workflows/guardrails.yml
name: guardrails
on: pull_request
jobs:
  secrets:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }
      - name: gitleaks (PR diff)
        run: |
          curl -sSL https://github.com/gitleaks/gitleaks/releases/download/v8.24.0/gitleaks_8.24.0_linux_x64.tar.gz | tar xz
          ./gitleaks git --log-opts="origin/${{ github.base_ref }}..HEAD" --redact --exit-code 1
  deps:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }
      - uses: actions/setup-node@v4
        with: { node-version: 22 }
      - run: npm ci --ignore-scripts
      - name: known vulnerabilities
        run: npx --yes osv-scanner@latest --lockfile=package-lock.json
      - name: new packages
        run: node scripts/check-new-deps.mjs origin/${{ github.base_ref }}

Kiểm tra bản mới nhất của gitleaks và các action trước khi dùng; pin theo version hoặc commit SHA. Script báo lỗi không có nghĩa là "cấm" mà là "cần người xem": reviewer kiểm tra rồi thêm vào deps-allowlist.txt kèm lý do.Check the latest gitleaks and action versions before use; pin to a version or SHA. A failing script doesn't mean "banned" but "a human should look": the reviewer checks, then adds it to deps-allowlist.txt with a reason.

required checkĐặt cả hai job là bắt buộc trong branch protection. Job không bắt buộc chỉ là gợi ý.Make both jobs required in branch protection. A non-required job is only a suggestion.
--ignore-scriptsPackage độc hại thường chạy mã trong postinstall. Cài không chạy script là giảm rủi ro ngay trong CI.Malicious packages usually run code in postinstall. Installing without scripts cuts that risk in CI.
--redactLog CI không in lại secret vừa tìm thấy, vì log CI cũng có thể bị lộ.The CI log doesn't reprint the secret it found; CI logs leak too.
Tuần 1 · cảnh báoWeek 1 · warncontinue-on-error: true. Đo cảnh báo nhầm, chỉnh allowlist mà không chặn ai.continue-on-error: true. Measure false positives, tune the allowlist, block no one.
Tuần 2 · chặnWeek 2 · blockRequired check. Bật chặn ngay ngày đầu mà 3 PR kẹt vì key mẫu trong test thì team sẽ đòi tắt CI.Required check. Block on day one, get 3 PRs stuck on sample keys, and the team will demand CI off.
05

Mục "AI-assisted" trong PR templateThe "AI-assisted" PR template section

Mục này phục vụ reviewer, để biết phải nhìn kỹ chỗ nào. Nó không dùng để chấm điểm người viết. Thử tick bên dưới để xem job ai-label phản ứng thế nào.This section serves the reviewer, telling them where to look hard. It does not score the author. Tick boxes below to see how the ai-label job reacts.

.github/pull_request_template.mdPR #142

AI-assisted

Phần do AI sinh:AI-generated parts: src/cart/discount.ts
ai-label →
Lựa chọnChoiceLý doReason
Ghi file/hàm, không ghi "% code AI"Files/functions, not "% AI code"Reviewer cần biết chỗ nào để đọc kỹ; con số % không đo được, không dùng đượcThe reviewer needs to know where to read closely; a % can't be measured or used
Checkbox, không hỏi mởCheckboxes, not open questionsĐiền trong 20 giây. Mục điền lâu sẽ bị bỏ trống20 seconds to fill. Slow sections get left blank
Có ô "Không dùng AI"A "No AI used" boxPhân biệt "không dùng" với "quên điền"; CI báo lỗi khi cả hai ô trốngTells "didn't use" from "forgot"; CI fails when both are empty
Không phán xétNo judgemental wordingKhai báo bị phạt thì người ta khai thiếu. Dấu vết chỉ có giá trị khi trung thựcPunish disclosure and people under-declare. A trace is only worth something when honest
Nhãn ai-assisted tự độngAutomatic ai-assisted labelCuối sprint, lọc theo nhãn là có số liệu: tỷ lệ PR dùng AI, số vòng review, bug sau mergeAt sprint end, filter by label for numbers: share of AI PRs, review rounds, post-merge bugs
06

Từ bản nháp đến "đã áp dụng 1 sprint"From draft to "applied for 1 sprint"

Để được duyệt, gửi team lead một trang tóm tắt, đừng gửi một bản nháp trống. Duyệt xong thì ghi tên + ngày vào cuối policy và commit vào docs/ai-usage-policy.md.To get approval, send the team lead a one-page brief, not a bare draft. Once approved, record name + date at the bottom and commit it as docs/ai-usage-policy.md.

Vì saoWhy2 tài khoản ChatGPT cá nhân có thể đang huấn luyện trên dữ liệu; CI chưa kiểm secret hay package mới2 personal ChatGPT accounts may train on our data; CI checks neither secrets nor new packages
Tốn gìCost~1 ngày công thiết lập; +~1 phút CI mỗi PR; ~20 giây/dev cho PR template~1 person-day setup; +~1 min CI per PR; ~20 s per dev for the template
Thay đổi gìChanges2 bạn chuyển sang tài khoản tổ chức; PR có package mới cần reviewer xem2 devs move to org accounts; PRs with new packages need a reviewer's look
Nếu không làmIf we don'tMột secret lộ = thu hồi key, kiểm tra log truy cập, có thể phải báo khách hàngOne leaked secret = revoke keys, audit access logs, maybe notify customers
Cách đoMeasureSố lần chặn, cảnh báo nhầm, % PR có khai báo, phản hồi retroBlocks, false positives, % PRs declared, retro feedback
D0
D1
D2
D3
D4
D5
D6
D7
D8
D9
D10
D0Họp 15 phút đọc policy cùng nhau; mọi người ghi "đã đọc" vào issue15-min meeting to read the policy; everyone ticks "read" on an issue
D1Merge PR template + guardrails.yml (cảnh báo) + pre-commit; quét toàn bộ lịch sử 1 lầnMerge template + guardrails.yml (warn) + pre-commit; one full-history scan
D2–5Ghi mọi cảnh báo: đúng hay nhầm? Chỉnh .gitleaks.toml, allowlistLog every alert: real or false? Tune .gitleaks.toml, allowlist
D6–9Chuyển sang required check. Ai bị chặn thì ghi lại: lý do có hợp lý không?Switch to required checks. Anyone blocked notes it: was it fair?
D10Retro với số liệu, sửa policy thành v1.1Retro with numbers, revise to v1.1

Số liệu cần có cuối sprintNumbers to have at sprint end

Chỉ sốMetricCách lấySourceĐể làm gìPurpose
PR có nhãn ai-assisted / tổng PRPRs labelled ai-assisted / totalLọc nhãnLabel filterAI được dùng nhiều đến đâuHow much AI is used
% PR điền mục AI-assisted% PRs with the section filledJob ai-label không báo lỗiai-label job passingMức tuân thủCompliance
gitleaks chặn (đúng / nhầm)gitleaks blocks (real / false)Log CI + ghi chép tuần 1CI logs + week-1 notesChỉnh allowlist; chứng minh giá trịTune allowlist; prove value
Package mới bị deps-check giữNew packages held by deps-checkLog CICI logsThấy rủi ro slopsquatting thậtSee real slopsquatting risk
Thời gian CI tăng thêmExtra CI timeSo trước/sauBefore/afterKiểm chứng phần "tốn gì"Check the "cost" claim
?Quy tắc nào khiến bạn khó chịu mà không thấy lợi ích gì?Which rule annoyed you without visible benefit?
?Có lúc nào bạn muốn dùng AI nhưng policy không nói rõ là được hay không?When did you want to use AI but the policy wasn't clear?
?Có lỗi nào lẽ ra quy trình phải bắt được nhưng đã lọt qua?What slipped through that the process should have caught?
07

Trước và sau M3Before and after M3

Trước (sau M2)Before (after M2)Sau M3After M3
Công cụToolsMỗi người tự chọnEveryone picks their own3 mức, có tiêu chí, có quy trình đề xuất3 tiers, criteria, a proposal process
Dữ liệu trong promptData in prompts"Cẩn thận nhé""Be careful"Bảng đỏ/vàng/xanh có ví dụRed/amber/green table with examples
SecretTuỳ ý thức từng ngườiIndividual disciplinePre-commit + CI chặn + quét lịch sửPre-commit + CI block + history scan
Package mớiNew packagesReviewer tự để ý (nếu nhớ)Reviewer notices (if they remember)deps-check hỏi registrydeps-check asks the registry
Code AI sinhAI codeKhông ai biết PR nào cóNobody knows which PRsNhãn ai-assisted + file cụ thểai-assisted label + specific files
Sự cốIncidentsKhông có kịch bảnNo playbookThu hồi key trong 1 giờ, không đổ lỗiRevoke within 1 hour, no blame
08

Cây quyết định 10 giâyA 10-second decision tree

Có secret, PII khách hàng
hoặc mã nguồn mật?
├─ Có  → KHÔNG. Dùng dữ liệu giả
│        hoặc mô tả bằng lời.
└─ Không
   └─ Code/dữ liệu của công ty?
      ├─ Có  → Chỉ công cụ ĐƯỢC DUYỆT
      └─ Không → Công cụ nào cũng được
Contains a secret, customer PII
or confidential source?
├─ Yes → NO. Use fake data
│        or describe it in words.
└─ No
   └─ Company code/data?
      ├─ Yes → APPROVED tools only
      └─ No  → Any tool
Code AI sinh sắp vào PR?
├─ Thêm package mới?
│    → deps-check phải qua
├─ Chạm auth/payment/admin?
│    → cần 2 approve
└─ Luôn luôn
     → có test + điền AI-assisted
AI code about to go into a PR?
├─ Adds a new package?
│    → deps-check must pass
├─ Touches auth/payment/admin?
│    → 2 approvals
└─ Always
     → tests + fill in AI-assisted
09

Anti-pattern

Anti-patternVì sao hỏngWhy it failsLàm thayDo instead
Policy 15 trang copy mẫu trên mạng15-page policy copied from the webKhông ai đọc, không khớp công cụ thậtNobody reads it; doesn't match real tools1–2 trang, viết từ bảng kê M21–2 pages, from the M2 inventory
Cấm hết AIBan all AINgười ta dùng chui bằng tài khoản cá nhânPeople use personal accounts in secretBa mức duyệt, có kênh đề xuấtThree tiers, a proposal channel
Policy chỉ là văn bảnPolicy is paper onlyNgày bận nhất, quy tắc bị quênForgotten on the busiest dayViệc máy kiểm được → pipelineMachine-checkable → pipeline
Bật chặn ngay ngày đầuBlock from day oneCảnh báo nhầm làm team đòi tắt CIFalse positives → team wants CI off1 tuần cảnh báo, rồi chặn1 week warn, then block
Chỉ có pre-commit hookOnly a pre-commit hookTắt được; clone mới không có hookCan be disabled; fresh clones lack itHook + CI required checkHook + CI required check
Chỉ chạy npm auditOnly npm auditPackage độc hại mới đăng chưa có CVEFresh malicious packages have no CVEThêm kiểm tra package mớiAdd a new-package check
Hỏi "% code do AI viết"Ask "% written by AI"Không đo được, không dùng đượcUnmeasurable, unusableHỏi file/hàm cụ thểAsk for files/functions
Phạt người khai báoPunish disclosureLần sau họ khai thiếuNext time they under-declareKhai báo là thông tin cho reviewerDisclosure is info for the reviewer
Lộ secret thì chỉ xoá commitLeaked secret → delete the commitVẫn nằm trong lịch sử, fork, log AIStill in history, forks, AI logsThu hồi key trước, dọn sauRevoke first, clean up after
Duyệt xong rồi bỏ đóApprove and forgetCông cụ AI đổi chính sách vài tháng một lầnAI tools change policy every few monthsXem lại mỗi quý, có số phiên bảnQuarterly review, versioned
10

Checklist M3M3 checklist

Policy

Pipeline

PR template

Done

11

Tự kiểm traSelf-check

Vì sao policy chỉ 1–2 trang, chi tiết đặt ở đâu?Why only 1–2 pages, and where does detail go?

Ngắn thì người ta đọc và nhớ. Pattern secret, ngưỡng tuổi package, allowlist đặt trong file cấu hình (.gitleaks.toml, deps-allowlist.txt, workflow CI).Short gets read and remembered. Secret patterns, age thresholds and allowlists live in config (.gitleaks.toml, deps-allowlist.txt, the CI workflow).

Đã có pre-commit hook, sao vẫn cần gitleaks trong CI?Pre-commit hook on — why still gitleaks in CI?

Hook chạy trên máy dev, có thể bị tắt hoặc chưa cài (clone mới). CI với required check thì không ai bỏ qua được.Hooks run locally and can be disabled or missing (fresh clone). A CI required check can't be skipped.

npm audit sạch, sao package mới vẫn nguy hiểm?npm audit is clean — why can a new package still be dangerous?

npm audit chỉ biết CVE đã công bố. Package mới đăng (slopsquatting) chưa có CVE. Phải kiểm tra tồn tại, tuổi, lượt tải, license.It only knows published CVEs. A fresh package (slopsquatting) has none. Check existence, age, downloads, licence.

Sao hỏi "file/hàm nào" thay vì "bao nhiêu %"?Why "which files" instead of "what %"?

Reviewer cần biết chỗ nào để đọc kỹ. Con số % không đo được và không giúp review.The reviewer needs to know where to read closely. A % can't be measured and doesn't help.

Lỡ dán .env vào ChatGPT. Việc đầu tiên?Pasted .env into ChatGPT. First move?

Coi như đã lộ: thu hồi và tạo key mới ngay (trong 1 giờ), báo team lead, ghi lại sự cố. Xoá đoạn chat không đủ.Treat it as leaked: revoke and reissue keys now (within 1 hour), tell the team lead, log it. Deleting the chat isn't enough.

Sao bật cảnh báo trước khi chặn?Why warn before block?

Để đo và chỉnh cảnh báo nhầm trước. Bị chặn sai vài lần, team sẽ đòi tắt CI.To measure and tune false positives first. A few wrong blocks and the team wants CI off.