Hooks van: & naar: syntax in yml om anonieme zoekopdrachten uit te schakelen

Hallo, ik wil de app opnieuw bouwen, inclusief enkele wijzigingen in een bestand om de zoekfunctie voor anonieme gebruikers uit te schakelen (meer dan alleen met css).

Kan iemand mij wat documentatie geven voor de syntaxis van deze hooks voor het from: & to: gedeelte?

    - replace:
        filename: "/var/www/discourse/app/assets/javascripts/discourse/app/components/search-menu.js"
        from: /get classNames()/
        to: |
          if (!this.currentUser) {return false;} get classNames()

Discourse accepteert de syntaxis nu, maar aan het einde van de rebuild mislukt het met

 Error: Parse Error at discourse/components/search-menu.gjs:88:7"
replace failed with the params {"filename"=>"/var/www/discourse/app/assets/javascripts/discourse/app/components/search-menu.gjs", "from"=>"/get classNames()/", "to"=>"if (!this.currentUser) {return false;} get classNames()\n"}

Er is een verborgen site-instelling om dat te bereiken:

rate_limit_search_anon_global_per_minute
1 like

Bedankt dat u dat aangeeft. Om het duidelijk te maken, wat is de naam van de verborgen site-instelling? En schakelt het zoeken voor anonieme gebruikers volledig uit, of worden alleen de resultaten verborgen? Ik zoek naar een manier om toegang op controller-niveau te blokkeren, dus ik vraag me af of die instelling alleen voldoende is of dat er nog steeds aangepaste code nodig is.

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.

Ik bedoel een niet-ingelogde gebruiker die een sessiecookie zou aanmaken om te doen alsof ze zijn ingelogd, maar misschien ga ik hier wat te ver, aangezien ik vermoed dat de currentUser-functie de sessiesleutel controleert.

:face_with_raised_eyebrow:

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

1 like

" 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

1 like

DISCOURSE_RATE_LIMIT_SEARCH_ANON_GLOBAL_PER_MINUTE: 0

maar aarzel niet om dit op controller-niveau te proberen:
/var/www/discourse/app/controllers/search_controller.rb
De wijziging: voeg 'if current_user.present?' toe na 'def show' en voeg een 'end' toe onderaan de voorwaarde.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.