Skip to content

データベース追加#2

Open
matuaya wants to merge 6 commits intomainfrom
memo-app-db
Open

データベース追加#2
matuaya wants to merge 6 commits intomainfrom
memo-app-db

Conversation

@matuaya
Copy link
Copy Markdown
Owner

@matuaya matuaya commented Nov 7, 2023

No description provided.

app.rb Outdated

get '/' do
result = conn.exec('SELECT * FROM memos ORDER BY id')
@memos = result.map { |table_row| table_row }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここは result.to_a と書いても同じ結果になりますね。

app.rb Outdated
get '/memos/:id' do
@id = params[:id]
@memo = @memos[@id]
memo = conn.exec("SELECT * FROM memos WHERE id = '#{params[:id]}'")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この書き方だと /memos/DELETE FROM memos のようなURLにアクセスすると、このSQLを壊せてしまいますね。
いわゆるSQLインジェクションと呼ばれるものです。pgを使って対策ができるものなので、対処方法を検討ください 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants