hdygxsj opened a new pull request, #13164:
URL: https://github.com/apache/dolphinscheduler/pull/13164

   <!--Thanks very much for contributing to Apache DolphinScheduler. Please 
review 
https://dolphinscheduler.apache.org/en-us/community/development/pull-request.html
 before opening a pull request.-->
   
   ## Purpose of the pull request
   
   close issue #12931
   
   Currently, the dolphinscheduler can be attacked by a CSRF in the following 
ways.
   
   1. First, someone exits the Dolphinscheduler site but does not clear the 
cookie
   2. The dolphinscheduler api can then be accessed via cookies by other sites 
or others to submit forms or obtain information without authorization. For 
example:
   
![12df10a45c9fc58e31460de00b5b65e](https://user-images.githubusercontent.com/35210666/207091750-bfd862f2-4ba8-46c0-9990-b6c12f2a5446.png)
   or
   ```html
    <form action="http://127.0.0.1:5173/dolphinscheduler/users/get-user-info"; 
method="get">
           <input type="submit" value="提交" />
       </form>
   ```
   
![c523c315e0fb2cff57c0a1101d7ce2a](https://user-images.githubusercontent.com/35210666/207091999-0b326e2b-81a7-47a0-a654-6dc6298d17c8.png)
   
   
![9e2506fceceed0bab2a380b57978967](https://user-images.githubusercontent.com/35210666/207091925-ca65d0af-6030-4665-9005-049ac09bf050.png)
   
   after this pr, when an attacker performs a CSRF attack, he will get a 403 
exception.
   
![e41b68640a4779bf3cd70fca4dbb354](https://user-images.githubusercontent.com/35210666/207092733-0afed6a9-3af3-430f-ab4c-05c2c0d634cf.png)
   
![e3530c14574a3738d7873ed2f24fd03](https://user-images.githubusercontent.com/35210666/207092757-65986d33-7419-4314-9c18-93af55955d83.png)
   
   
   ## Brief change log
   
   I thought it would take a lot of work to introduce Spring security 
dependencies, so I added a CsrfTokenInterceptor to implement csrf defense.
   The CsrfTokenInterceptor does not intercept requests with the token in the 
http request header to ensure that the api is accessible through the token.
   The CsrfTokenInterceptor will get the X-CSRF-TOKEN from the http request 
header or the _csrf from the request paramter and verify their accuracy.
   And changed the ui module to add the request header X-CSRF-TOKEN when making 
an http request
   In the above way, dolphinscheduler can be protected from CSRF attacks only 
by ensuring that the attacker cannot obtain a correct csrf token
   
   ## Verify this pull request
   
   <!--*(Please pick either of the following options)*-->
   
   This pull request is code cleanup without any test coverage.
   
   *(or)*
   
   This pull request is already covered by existing tests, such as *(please 
describe tests)*.
   
   (or)
   
   This change added tests and can be verified as follows:
   
   <!--*(example:)*
   - *Added dolphinscheduler-dao tests for end-to-end.*
   - *Added CronUtilsTest to verify the change.*
   - *Manually verified the change by testing locally.* -->
   
   (or)
   
   If your pull request contain incompatible change, you should also add it to 
`docs/docs/en/guide/upgrede/incompatible.md`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to