jichanan / danbi

0 stars 0 forks source link

hits_refactoring #11

Closed jichanan closed 1 year ago

jichanan commented 1 year ago

Related Issue

Motivation ๐Ÿง

Key Changes ๐Ÿ—


To Reviewers ๐Ÿ™

-

Screenshot

-

Reference

-

jichanan commented 1 year ago
title, context, userid = cur.execute("SELECT title, context, userid FROM board where id=%s", [id]).fetchone()

'int' object has no attribute 'fetchone' ์˜ค๋ฅ˜ ๋ฐœ์ƒ

cur.execute(f'INSERT INTO hit_count (userid, board_no, hit_time) VALUES ({session_id}, {id}, {hit_time})')

์ด๊ฑฐ ์ง„์งœ f-string์œผ๋กœ ํ•˜๋ฉด ๋ณด๊ธฐ ์ฐธ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์„œ ํ•ด๋ณด๋‹ˆ๊น ์•Œ ์ˆ˜ ์—†๋Š” ์˜ค๋ฅ˜๋“ค์ด..

1๋ฒˆ์งธ ์˜ค๋ฅ˜: (1054, "Unknown column "dkswlcks77" in 'where clause'") โ† ํฌ์•ˆํ•˜๊ฒŒ {session_id}๋งŒ ๋”ฐ์˜ดํ‘œ๋กœ ๊ฐ์‹ธ์ฃผ๋ฉด ์ •์ƒ์ž‘๋™ํ•จ cur.execute(f'UPDATE hit_count SET hit_time = {current_time} WHERE userid = "{session_id}" AND board_no = {id}') โ†์ด๋Ÿฐ์‹์œผ๋กœ <์ฐธ๊ณ ์‚ฌํ•ญ> print(sessionid) // 'dkswlcks77'_ print(type(session_id)) // str print(id) // '257' print(type(id)) // str hit_count ํ…Œ์ด๋ธ”์˜ userid์™€ board_no ๋‘˜ ๋‹ค varchar %s ํฌ๋งทํŒ…์€ ์ •์ƒ์ž‘๋™

2๋ฒˆ์งธ ์˜ค๋ฅ˜: cur.execute(f'UPDATE hit_count SET hit_time = {current_time} WHERE userid = {session_id} AND board_no = {id}') ์—๋Ÿฌ1

+ f-string์€ SQL Injection์— ์ทจ์•ฝ(?)

ํ•จ์ˆ˜ํ™œ์šฉ(์ฝ”๋“œ์— ์ด๋ฆ„ ๋ถ™์ด๊ธฐ)

๋ˆ„๋‚˜๊ฐ€ ์•Œ๋ ค์ค€๋Œ€๋กœ ๊ธฐ๋Šฅ๋‹จ์œ„๋กœ ์ชผ๊ฐœ๋‹ˆ๊น ์ฝ”๋“œ๋ฅผ ํ•ด์„ํ•  ํ•„์š”์—†์ด ์‰ฝ๊ฒŒ ๋ญ” ์ฝ”๋“œ์ธ์ง€ ๋น ๋ฅด๊ฒŒ ์•Œ ์ˆ˜ ์žˆ์–ด์„œ ์ข‹์€ ๊ฒƒ ๊ฐ™์•„! ํ˜น์‹œ ๋ญ ์ž˜๋ชป ์ชผ๊ฐฐ๊ฑฐ๋‚˜ ๋„ค์ด๋ฐ์ด ๋ณ„๋กœ๋ผ๊ฑฐ๋‚˜ ๋ณด์™„ํ•  ์  ์žˆ์œผ๋ฉด ์•Œ๋ ค์ค˜!

- ๋ณต์Šต (์ฐธ๊ณ ๋ฌธํ—Œ:ํ˜ผ๊ณตํŒŒ) ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค๋ฉด ์ฝ”๋“œ์— ์ด๋ฆ„์„ ๋ถ™์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ฝ”๋“œ์— ์ด๋ฆ„์„ ๋ถ™์ด๋ฉด ์‰ฝ๊ฒŒ ์ฝ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด ์ฃผ์„์ด ์—†์–ด๋„ ์‰ฝ๊ฒŒ ์ฝ”๋“œ๋ฅผ ์ดํ•ด ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.(๋ฌผ๋ก  area์™€ circumference๋ผ๋Š” ๋‹จ์–ด์˜ ์˜๋ฏธ๋ฅผ ๋ชจ๋ฅด๋ฉด ํž˜๋“ค๊ฒ ์ง€๋งŒ์š”) ํ•จ์ˆ˜ํ™”์˜ˆ์‹œ ๊ทธ๋Ÿฐ๋ฐ ์ฝ”๋“œ๊ฐ€ ๊ธธ์–ด์ ธ์„œ ์˜คํžˆ๋ ค ๋ณต์žกํ•ด์กŒ๋‹ค๊ณ  ์ƒ๊ฐํ• ์ˆ˜๋„ ์žˆ๋Š”๋ฐ, ํ•จ์ˆ˜ ๋ถ€๋ถ„์€ ์ƒ๋žตํ•˜๊ณ  ์ฝ”๋“œ ๋ณธ๋ฌธ ๋ถ€๋ถ„๋งŒ ์‚ดํŽด๋ณด๋ฉด ์ฃผ์„์ด ์ „ํ˜€์—†์–ด๋„ ์ฝ”๋“œ๋งŒ ์ฝ๊ณ  ๋ฌด์—‡์„ ํ•˜๋Š” ์ฝ”๋“œ์ธ์ง€ ์‰ฝ๊ฒŒ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ ํ•œ์ค„์˜ ์ฝ”๋“œ๋ผ๋„ ์˜๋ฏธ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๋ฉด ํ•จ์ˆ˜๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

SooDevv commented 1 year ago

์ง€์ฐฌ์•„~! ๋ˆ„๋‚˜๊ฐ€ reviewํ•ด์ค€๊ฑฐ๋ฅผ ๊ณ ์น  ๋•Œ, ์ด๋ ‡๊ฒŒ ๋”ฐ๋กœ PR ๋‚ ๋ฆด ํ•„์š” ์—†์ด ์ด์ „ PR์—์„œ ๊ณ„์† ์ž‘์—…ํ•ด๋„๋ผ!

PR ํ๋ฆ„์„ ์ •๋ฆฌํ•˜์ž๋ฉด,

  1. 1์ฐจ๋กœ ์ž‘์—…ํ•œ๊ฑฐ PR ๋‚ ๋ฆฌ๊ธฐ
  2. review ๋ฐ›๊ธฐ
  3. review ๋ฐ›์€๊ฑฐ์—์„œ ์ˆ˜์ •ํ•  ๋ถ€๋ถ„์ด ์žˆ์œผ๋ฉด ์ˆ˜์ •ํ•˜๊ณ  commit & push (pushํ•˜๋ฉด ํ•ด๋‹น PR์—์„œ ๋ณ€๊ฒฝํ•œ ๋ถ€๋ถ„์„ Commit๋‹จ์œ„๋กœ ๋ณผ ์ˆ˜ ์žˆ์Œ)
  4. reviewer ๊ฐ€ approved ํ•˜๋ฉด PR merge ํ•˜๊ธฐ