Skip to content

Commit b27d315

Browse files
committed
Ruby: add an example of protect_from_forgery with: :exception
1 parent c1a51d9 commit b27d315

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ruby/ql/test/query-tests/security/cwe-352/railsapp/app/controllers/articles_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
class ArticlesController < ApplicationController
2-
prepend_before_action :user_authored_article?, only: [:delete_authored_article]
2+
prepend_before_action :user_authored_article?, only: [:delete_authored_article, :change_title]
3+
4+
# GOOD: `with: :exception` provides more effective CSRF protection than
5+
# `with: :null_session` or `with: :reset_session`.
6+
protect_from_forgery with: :exception, only: [:change_title]
37

48
def delete_authored_article
59
article.destroy

0 commit comments

Comments
 (0)