0Pricing
Vibe Coding · 강의

인공지능 코드 보안 기초

인공지능이 자주 놓치는 위험을 피하십시오.

인공지능 코드 보안 기초은(는) CoddyKit의 무료 Vibe Coding 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Vibe Coding 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Vibe Coding 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

AI Writes Fast — Sometimes Unsafely

AI is brilliant at getting something working quickly. But "working" and "safe" aren't the same. AI often leaves real apps open to attacks because it optimizes for the happy path, not for hostile users.

The good news: a handful of habits catch most problems, and you can ask AI to apply them. This lesson covers the security risks vibe coders hit most.

Never Put Secrets in Code

The #1 mistake: pasting an API key or password directly into your code. If that code goes to GitHub, the key is public forever — bots scan for leaked keys within minutes.

Secrets belong in environment variables, never in the source. Spot the difference below.

// DANGER: key is hardcoded and will leak
const apiKey = 'sk-live-abc123realkey';

// SAFE: key comes from the environment, not the code
const apiKey = process.env.API_KEY;

if (!apiKey) {
  throw new Error('API_KEY is missing — set it in your .env file');
}

Keep Secrets Out of Git

Store secrets in a .env file, and make sure Git ignores that file so it never gets committed. One line in .gitignore does it.

Ask your AI tool to set this up correctly from the start.

Set up environment variables for this project:
- create a .env file with API_KEY=
- add .env to .gitignore so it's never committed
- create a .env.example with empty placeholders to commit instead
- show me where the code reads process.env.API_KEY

Never Trust User Input

The golden rule of security: anything a user can type, a user can lie about. Attackers send broken, oversized, or malicious input on purpose. Your code must validate it.

Here's a basic guard that checks input before using it.

function createUser(input) {
  if (typeof input.email !== 'string' || !input.email.includes('@')) {
    return { error: 'Invalid email' };
  }
  if (input.age < 0 || input.age > 150) {
    return { error: 'Invalid age' };
  }
  return { ok: true };
}

console.log(createUser({ email: 'bad', age: 30 }));
console.log(createUser({ email: 'a@b.com', age: 30 }));

SQL Injection: A Classic AI Slip

If AI builds your database query by gluing user input into a string, an attacker can inject their own commands and steal or delete data. This is SQL injection.

The fix is parameterized queries — the database treats input as data, never as commands. Always ask AI to use them.

// DANGER: user input glued straight into the query
db.query("SELECT * FROM users WHERE email = '" + email + "'");

// SAFE: parameterized — the ? is filled in safely
db.query('SELECT * FROM users WHERE email = ?', [email]);

Ask AI to Review for Security

You can turn the AI into a security reviewer. Paste your code and ask it to hunt for vulnerabilities specifically — it's much better at finding them when you ask directly.

Review this code for security problems. Specifically check for:
- hardcoded secrets or API keys
- unvalidated user input
- SQL injection
- missing authentication checks
List each issue, why it's risky, and the fix. Here is the code: <paste>

Protect What Should Be Private

AI often builds an endpoint that returns data without checking who is asking. That means anyone could read another user's data just by changing an ID in the URL.

Every sensitive action needs an authorization check: is this user allowed to do this?

// DANGER: anyone can read any order by guessing the id
app.get('/orders/:id', (req, res) => {
  res.json(getOrder(req.params.id));
});

// SAFE: only the owner can see their order
app.get('/orders/:id', (req, res) => {
  const order = getOrder(req.params.id);
  if (order.userId !== req.user.id) return res.status(403).end();
  res.json(order);
});

Keep Dependencies Updated

Your app uses many packages written by others. Some have known security holes. Outdated dependencies are one of the most common ways apps get hacked.

A quick command checks for known vulnerabilities, and AI can help you understand the results.

# Check installed packages for known vulnerabilities
npm audit

# Then ask AI:
# "npm audit reports 3 high-severity issues in <package>.
#  Explain the risk in plain English and tell me the safest way to fix it."

Don't Leak Errors to Users

When something breaks, AI-generated code sometimes shows the raw error — including file paths, database details, or stack traces. That's a gift to attackers.

Log details privately on the server, but show users a generic, friendly message.

try {
  doRiskyThing();
} catch (err) {
  console.error('Internal error:', err); // private log
  res.status(500).json({ error: 'Something went wrong. Please try again.' });
  // never send err.stack or err.message to the user
}

A Security Checklist You Can Reuse

Before you ship anything, run through this. Paste it to your AI and ask it to verify each item against your code.

  • No secrets in the code or Git history.
  • All user input validated.
  • Database queries are parameterized.
  • Sensitive routes check who is logged in and what they're allowed to do.
  • Dependencies audited and updated.
  • Errors logged privately, generic messages to users.

Security Is a Conversation, Not a One-Time Step

You won't catch everything, and that's fine. The mindset that protects you: assume AI code is insecure until reviewed, ask security questions every time you add a feature, and re-run your checklist before each deploy.

Treat the AI as a careful partner you actively interrogate — not an oracle you blindly trust.

Quick Check

Your AI assistant generates a login feature and hardcodes the database password right in the source file. What should you do?

Recap: Safe by Habit

AI ships fast but skips safety, so you supply the safety. You learned to: keep secrets out of code, validate all input, use parameterized queries, add authorization checks, audit dependencies, and hide raw errors.

Best of all, you can ask AI to review for these exact issues and run a checklist before every deploy. Next: keeping your code clean and maintainable.

자주 묻는 질문

“인공지능 코드 보안 기초” 강의는 무료인가요?

네 — “인공지능 코드 보안 기초” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Vibe Coding 강의 전체를 잠금 해제할 수 있습니다. Vibe Coding 강의에는 총 4개의 강의가 포함되어 있습니다.

“인공지능 코드 보안 기초”에서 뭘 배우나요?

인공지능이 자주 놓치는 위험을 피하십시오. 브라우저에서 직접 실행하는 실습 코드로 Vibe Coding을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Vibe Coding을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Vibe Coding은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.

“인공지능 코드 보안 기초” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Vibe Coding 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Vibe Coding 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 인공지능으로 테스트 추가하기
  2. 인공지능 코드 보안 기초
  3. 유지 관리 가능한 코드 만들기
  4. 성능과 비용
← Vibe Coding(으)로 돌아가기