Class: Shugoi::RenderHandler
- Inherits:
-
Object
- Object
- Shugoi::RenderHandler
- Defined in:
- lib/shugoi/render_handler.rb
Overview
Traite la requête /__shugoi/render : vérifie token + grant, sert le HTML stocké. Parité avec renderResponseData + handleRender (render.ts).
Instance Method Summary collapse
-
#initialize(config, token_signer, html_store, config_cache) ⇒ RenderHandler
constructor
A new instance of RenderHandler.
-
#render_data(token, mid, grant, ip) ⇒ Hash
{ html: … } ou { error: "not_found" }.
Constructor Details
#initialize(config, token_signer, html_store, config_cache) ⇒ RenderHandler
Returns a new instance of RenderHandler.
7 8 9 10 11 12 |
# File 'lib/shugoi/render_handler.rb', line 7 def initialize(config, token_signer, html_store, config_cache) @config = config @token_signer = token_signer @html_store = html_store @config_cache = config_cache end |
Instance Method Details
#render_data(token, mid, grant, ip) ⇒ Hash
Returns { html: … } ou { error: "not_found" }.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/shugoi/render_handler.rb', line 19 def render_data(token, mid, grant, ip) return { error: "not_found" } if token.to_s.empty? || token.length < 16 || token.length > 300 # Le token doit appartenir à CE siteKey (CRITIQUE 1 §7bis). tok_site_key = token.split(":")[0] return { error: "not_found" } if tok_site_key != @config.site_key # Expiration du token. tok_ts = token.split(":")[1].to_i return { error: "not_found" } if !tok_ts.zero? && Utils.now_ms - tok_ts > HtmlStore::TOKEN_TTL_MS # Anti-bypass token-only : grant valide requis. return { error: "not_found" } unless @token_signer.verify_render_grant(mid, grant, token, ip, @config.site_key) content_replace_on = content_replace_flag?(token) html = @html_store.read(token) return { html: inject_notice(html, mid) } if html # Fallback content-replace OFF : renvoie le HTML du site. unless content_replace_on site_html = @html_store.site_html(tok_site_key) return { html: inject_notice(site_html, mid) } if site_html end return { error: "not_found" } unless @token_signer.verify_token(token) { error: "not_found" } end |