lint_flag_res_send_usage 955 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.js"
  16. if [[ "$POTENTIAL_SEND_USAGE" == "$HELPER_MODULE" ]]; then
  17. exit 0
  18. fi
  19. for file in ${POTENTIAL_SEND_USAGE}; do
  20. if [[ "$file" == "$HELPER_MODULE" ]]; then
  21. continue
  22. fi
  23. cat <<MSG >&2
  24. ERROR: $file contains a potential use of 'res.send'.
  25. ---
  26. $(grep -n -C 3 "$file" --regex "\.send\b" --regex "\bsend(")
  27. ---
  28. Using 'res.send' is prone to introducing XSS vulnerabilities.
  29. Consider using 'res.json' or one of the helpers in $HELPER_MODULE.
  30. If this is a false-positive, consider using a more specific name than 'send'
  31. for your newly introduced function.
  32. Links:
  33. - https://github.com/overleaf/internal/issues/6268
  34. MSG
  35. exit 1
  36. done