Hooks מ: & ל: תחביר ב-yml

סיכום מבוסס בינה מלאכותית

The user opcourdis wanted to disable the search feature for anonymous users in Discourse and initially attempted to do so using hooks in app.yml with a replace command, but encountered an error [/#370952/1]. They were then directed to a hidden site setting, DISCOURSE_RATE_LIMIT_SEARCH_ANON_GLOBAL_PER_MINUTE, by Falco and Michael12, which, when set to 0, effectively disables search for anonymous users [/#370952/4]. This results in the search page being unreachable and the search button returning a rate limit error. opcourdis also suggests hiding the search button with CSS.

Further security considerations were raised regarding the possibility of bypassing this restriction through session cookies [/#370952/5], which Falco acknowledged as a potential security issue and encouraged reporting to HackerOne. opcourdis clarified they were simply exploring potential vulnerabilities. A more thorough, but ultimately not persistent after a restart, solution involved modifying the search_controller.rb file [/#370952/4]. Finally, opcourdis expresses gratitude for Falco’s assistance, and offers the controller modification again as a more thorough approach [/#370952/9].

היי, הייתי רוצה לבנות מחדש את האפליקציה כולל שינוי בקובץ מסוים כדי להשבית את תכונת החיפוש למשתמשים אנונימיים. (יותר מסתם עם CSS)

האם מישהו יכול לספק לי תיעוד לתחביר של ה-hooks האלה עבור החלק של from: ו-to:?

replace
filename:“/var/www/discourse/app/controllers/search_controller.rb”
from:
to:

ב-search_controller.rb, אני רק רוצה להחליף את שורה 12 ב-
def show
ב-
def show
if current_user.present?

ושורה 76
format.json { render_json_dump(serializer) }
ב-
format.json { render_json_dump(serializer) }
end

ישנה הגדרת אתר נסתרת כדי להשיג זאת:

rate_limit_search_anon_global_per_minute

תודה שהצבעת על כך. רק כדי להבהיר, מה שם הגדרת האתר הנסתר? והאם היא משביתה לחלוטין את החיפוש עבור משתמשים אנונימיים, או רק מסתירה את התוצאות? אני מחפש דרך לחסום גישה ברמת הבקר (controller), אז תוהה אם ההגדרה הזו לבדה מספיקה או שעדיין נדרש קוד מותאם אישית.

Thanks for providing with the variable, with this documentation I could make it work.

So I modified the app.yml with the following, saved, then ./launcher restart app(no rebuild needed)

env:
  DISCOURSE_RATE_LIMIT_SEARCH_ANON_GLOBAL_PER_MINUTE: 0

Now the /search page is unreachable = great
Now the front end search button instantly returns : you’ve performed this action too many times = great
You may hide the search button with :

.anon #search-button {
	display: none !important;
}

But the question is : is this thorough? Can anyone just create a simple session cookie to make it look like they are connected so that they can access the content of the site through searches?

More thorough but uncomplete solution :

The file is : /var/www/discourse/app/controllers/search_controller.rb
The modification : add “if current_user.present?” after “def show” and add an “end” at the bottom of the condition.

However I could not make it persistent after restart, so anybody is welcome to tell how to make it persistent after restart with the app.yml hooks after_code replace: feature.

As in log in to do searches?

On the OP you specified that you want to

And this is what this setting does.

Of course it won’t affect uses who are logged in.

אני מתכוון למשתמש שאינו מחובר, שיצור עוגיית סשן כדי להתחזות למחובר, אבל אולי אני חושב רחוק מדי כאן, כיוון שאני מניח שפונקציית currentUser בודקת את מפתח הסשן.

:face_with_raised_eyebrow:

That would be a security issue. If you can achieve that make sure to report to HackerOne

" That would be a security issue. If you can achieve that make sure to report to HackerOne"

No, I am new to discourse, I cannot even quote properly :slight_smile: , I was just asking, maybe there was some discourse engineer around :slight_smile: ; anyway, we got our solution to this thread thanks to you Falco

DISCOURSE_RATE_LIMIT_SEARCH_ANON_GLOBAL_PER_MINUTE: 0

but feel free to try this at the controller level:
/var/www/discourse/app/controllers/search_controller.rb
The modification: add "if current_user.present?" after "def show" and add an "end" at the bottom of the condition.