Skip to content

5465 ajax success replace - #5466

Draft
christinach wants to merge 2 commits into
mainfrom
5465-ajax-success-replace
Draft

5465 ajax success replace#5466
christinach wants to merge 2 commits into
mainfrom
5465-ajax-success-replace

Conversation

@christinach

Copy link
Copy Markdown
Member

No description provided.

- Use native fetch and remove ajax:success - dont rely on rails ujs

related to #5465
document.querySelector('.blacklight-modal') ||
document.getElementById('blacklight-modal');
if (modalEl) {
modalEl.innerHTML = body;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

address semgrep failure

    app/assets/javascripts/application.js
   ❯❯❱ javascript.browser.security.insecure-document-method.insecure-document-method
          User controlled data in methods like `innerHTML`, `outerHTML` or `document.write` is an anti-pattern
          that can lead to XSS vulnerabilities                                                                
          Details: https://sg.run/LwA9                                                                        
                                                                                                              
           55┆ modalEl.innerHTML = body;
            ⋮┆----------------------------------------
           59┆ wrapper.innerHTML = body;
                            
  BLOCKING CODE RULES FIRED:
    javascript.browser.security.insecure-document-method.insecure-document-method

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

same failure for bearer

Replicate some of the rails ujs login in csrf_form_helper:
- read the csrf meta tags with getCsrfToken() and getCsrfParam()
  - normalizeOptions sets method and credentials
  - adds X-CSRF_Token and X-Requested-With and Accept
- fetchWithCsrf() -> equivelant to rails ajax call
- refreshCSRFTokens() -> updates hidden authenticity token in forms. we hook it with DOMContentLoaded
- a public API Orangelight.CsrfFormHelper and window.CsrfFormHelper similar to rails ajax

related to #5465
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 95.231%. remained the same
when pulling 11553b5 on 5465-ajax-success-replace
into e4ec6f6 on main.

@christinach
christinach marked this pull request as ready for review January 13, 2026 16:13
@christinach
christinach marked this pull request as draft January 13, 2026 16:17
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.

3 participants