lint_flag_res_send_usage 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. set -e
  3. POTENTIAL_SEND_USAGE=$(\
  4. grep \
  5. --files-with-matches \
  6. --recursive \
  7. app.mjs \
  8. app/ \
  9. modules/*/app \
  10. test/acceptance/ \
  11. modules/*/test/acceptance/ \
  12. --regex "\.send\b" \
  13. --regex "\bsend(" \
  14. )
  15. HELPER_MODULE="app/src/infrastructure/Response.mjs"
  16. MOCK_MODULE="test/acceptance/src/mocks/MockResponse.mjs"
  17. if [[ "$POTENTIAL_SEND_USAGE" == "$HELPER_MODULE" ]] || [[ "$file" == "$MOCK_MODULE" ]]; then
  18. exit 0
  19. fi
  20. for file in ${POTENTIAL_SEND_USAGE}; do
  21. if [[ "$file" == "$HELPER_MODULE" ]] || [[ "$file" == "$MOCK_MODULE" ]]; then
  22. continue
  23. fi
  24. cat <<MSG >&2
  25. ERROR: $file contains a potential use of 'res.send'.
  26. ---
  27. $(grep -n -C 3 "$file" --regex "\.send\b" --regex "\bsend(")
  28. ---
  29. Using 'res.send' is prone to introducing XSS vulnerabilities.
  30. Consider using 'res.json' or one of the helpers in $HELPER_MODULE.
  31. If this is a false-positive, consider using a more specific name than 'send'
  32. for your newly introduced function.
  33. Links:
  34. - https://github.com/overleaf/internal/issues/6268
  35. MSG
  36. exit 1
  37. done