You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "shahar1 (via GitHub)" <gi...@apache.org> on 2024/06/08 19:54:25 UTC

[PR] Add CSRF protection to "/logout" [airflow]

shahar1 opened a new pull request, #40145:
URL: https://github.com/apache/airflow/pull/40145

   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   closes: #33030
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add CSRF protection to "/logout" [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #40145:
URL: https://github.com/apache/airflow/pull/40145#discussion_r1632183386


##########
airflow/providers/fab/auth_manager/security_manager/override.py:
##########
@@ -57,8 +57,10 @@
     AuthOAuthView,
     AuthOIDView,
     AuthRemoteUserView,
+    AuthView,
     RegisterUserModelView,
 )
+from flask_appbuilder.views import expose

Review Comment:
   I guess this import is causing the DB access.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add CSRF protection to "/logout" [airflow]

Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on code in PR #40145:
URL: https://github.com/apache/airflow/pull/40145#discussion_r1636359429


##########
airflow/www/templates/appbuilder/navbar_right.html:
##########
@@ -83,7 +83,12 @@
         <li><a href="{{user_profile_url}}"><span class="material-icons">account_circle</span>{{_("Your Profile")}}</a></li>
         <li role="separator" class="divider"></li>
       {% endif %}
-      <li><a href="{{auth_manager.get_url_logout()}}"><span class="material-icons">exit_to_app</span>{{_("Log Out")}}</a></li>
+      <li class="dropdown">
+        <form method="POST" action="{{auth_manager.get_url_logout()}}">
+        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
+        <button type="submit" class="btn btn-link"><span class="material-icons">exit_to_app</span>{{_("Log Out")}}</button>

Review Comment:
   Thanks for the suggestion :) 
   I didn't see your message in time, yet I managed to implement it using a `<button>` instead and matching the styles.
   
   ![image](https://github.com/apache/airflow/assets/60007259/9b2e7b5e-e8f3-4b14-ac83-4c8d697232d3)



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add CSRF protection to "/logout" [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #40145:
URL: https://github.com/apache/airflow/pull/40145#issuecomment-2161299140

   > So I see no other good choice, but marking test_role_and_permission_endpoint.py as a db test.
   
   Yep. Saw the marker. Indeed that's simpler.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add CSRF protection to "/logout" [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #40145:
URL: https://github.com/apache/airflow/pull/40145


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add CSRF protection to "/logout" [airflow]

Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on PR #40145:
URL: https://github.com/apache/airflow/pull/40145#issuecomment-2156190752

   General question - Should Non-DB tests for FAB provider be skipped? (currently they fail)


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add CSRF protection to "/logout" [airflow]

Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on PR #40145:
URL: https://github.com/apache/airflow/pull/40145#issuecomment-2161281732

   > I think we also need a newsfragment for that one. While it can be treated as 'security fix" it also potentially breaks somoene workflow if they have some non-CSRF logout integrated somewhere in their setup.
   
   I will add one.
   I also checked locally - I managed to reproduce the errors, with or without the change, when running the following command:
   `breeze testing non-db-tests --parallel-test-types "Always Providers[fab] WWW"`
   
   So I see no good other choice, but marking `test_role_and_permission_endpoint.py` as a db test.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add CSRF protection to "/logout" [airflow]

Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on PR #40145:
URL: https://github.com/apache/airflow/pull/40145#issuecomment-2156155965

   I'd be happy for some minor UI help with alignment and color (my CSS abilities are good as my french 😅):
   
   ![image](https://github.com/apache/airflow/assets/60007259/af5be93b-3c5f-42b2-8530-bbbdbfdc4ba7)
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add CSRF protection to "/logout" [airflow]

Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on code in PR #40145:
URL: https://github.com/apache/airflow/pull/40145#discussion_r1636359429


##########
airflow/www/templates/appbuilder/navbar_right.html:
##########
@@ -83,7 +83,12 @@
         <li><a href="{{user_profile_url}}"><span class="material-icons">account_circle</span>{{_("Your Profile")}}</a></li>
         <li role="separator" class="divider"></li>
       {% endif %}
-      <li><a href="{{auth_manager.get_url_logout()}}"><span class="material-icons">exit_to_app</span>{{_("Log Out")}}</a></li>
+      <li class="dropdown">
+        <form method="POST" action="{{auth_manager.get_url_logout()}}">
+        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
+        <button type="submit" class="btn btn-link"><span class="material-icons">exit_to_app</span>{{_("Log Out")}}</button>

Review Comment:
   Thanks for the suggestion :) 
   I didn't see your message in time, yet I implemented it using a `<button>` instead and matching the styles.
   It seems to achieve the same effect:
   
   ![image](https://github.com/apache/airflow/assets/60007259/9b2e7b5e-e8f3-4b14-ac83-4c8d697232d3)



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add CSRF protection to "/logout" [airflow]

Posted by "bbovenzi (via GitHub)" <gi...@apache.org>.
bbovenzi commented on code in PR #40145:
URL: https://github.com/apache/airflow/pull/40145#discussion_r1635308329


##########
airflow/www/templates/appbuilder/navbar_right.html:
##########
@@ -83,7 +83,12 @@
         <li><a href="{{user_profile_url}}"><span class="material-icons">account_circle</span>{{_("Your Profile")}}</a></li>
         <li role="separator" class="divider"></li>
       {% endif %}
-      <li><a href="{{auth_manager.get_url_logout()}}"><span class="material-icons">exit_to_app</span>{{_("Log Out")}}</a></li>
+      <li class="dropdown">
+        <form method="POST" action="{{auth_manager.get_url_logout()}}">
+        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
+        <button type="submit" class="btn btn-link"><span class="material-icons">exit_to_app</span>{{_("Log Out")}}</button>

Review Comment:
   A few css suggestions:
   
   - Make the submit button a link:
    ```
   <a
     href="javascript:{}"
     onclick="document.getElementById('logout').submit();" // add the id to the form
    >
     <span class="material-icons">exit_to_app</span>
     {{_("Log Out")}}
   </a>
   ```
   - You'll need to match the styles from `.dropdown-menu > li > a > .material-icons` in material-icons.css and from `.dropdown-menu > li > a` in `bootstrap-theme.css` 
   



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add CSRF protection to "/logout" [airflow]

Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on PR #40145:
URL: https://github.com/apache/airflow/pull/40145#issuecomment-2156387484

   > > General question - Should Non-DB tests for FAB provider be skipped? (currently they fail)
   > 
   > I think by modifying logout and adding decorator, some of the tests simply started requiring database - have not looked in detail, but that's essentially what is happening here. I guess it can be fixed by changing the test code to not trigger DB operations in those tests (preferrable) or marking them as db_tests.
   
   It makes sense, I'll check it out


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add CSRF protection to "/logout" [airflow]

Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on code in PR #40145:
URL: https://github.com/apache/airflow/pull/40145#discussion_r1632099581


##########
airflow/www/templates/appbuilder/navbar_right.html:
##########
@@ -83,7 +83,12 @@
         <li><a href="{{user_profile_url}}"><span class="material-icons">account_circle</span>{{_("Your Profile")}}</a></li>
         <li role="separator" class="divider"></li>
       {% endif %}
-      <li><a href="{{auth_manager.get_url_logout()}}"><span class="material-icons">exit_to_app</span>{{_("Log Out")}}</a></li>
+      <li class="dropdown">
+        <form method="POST" action="{{auth_manager.get_url_logout()}}">
+        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
+        <button type="submit" class="btn btn-link"><span class="material-icons">exit_to_app</span>{{_("Log Out")}}</button>

Review Comment:
   I'd be happy for help with alignment and color (my CSS abilities are good as my french 😅):
   
   ![image](https://github.com/apache/airflow/assets/60007259/af5be93b-3c5f-42b2-8530-bbbdbfdc4ba7)



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add CSRF protection to "/logout" [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #40145:
URL: https://github.com/apache/airflow/pull/40145#issuecomment-2156347134

   > General question - Should Non-DB tests for FAB provider be skipped? (currently they fail)
   
   I think by modifying logout and adding decorator, some of the tests simply started requiring database - have not looked in detail, but that's essentially what is happening here. I guess it can be fixed by changing the test code to not trigger DB operations in those tests (preferrable) or marking them as db_tests.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add CSRF protection to "/logout" [airflow]

Posted by "bbovenzi (via GitHub)" <gi...@apache.org>.
bbovenzi commented on code in PR #40145:
URL: https://github.com/apache/airflow/pull/40145#discussion_r1635308329


##########
airflow/www/templates/appbuilder/navbar_right.html:
##########
@@ -83,7 +83,12 @@
         <li><a href="{{user_profile_url}}"><span class="material-icons">account_circle</span>{{_("Your Profile")}}</a></li>
         <li role="separator" class="divider"></li>
       {% endif %}
-      <li><a href="{{auth_manager.get_url_logout()}}"><span class="material-icons">exit_to_app</span>{{_("Log Out")}}</a></li>
+      <li class="dropdown">
+        <form method="POST" action="{{auth_manager.get_url_logout()}}">
+        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
+        <button type="submit" class="btn btn-link"><span class="material-icons">exit_to_app</span>{{_("Log Out")}}</button>

Review Comment:
   A few css suggestions:
   
   - Make the submit button a link:
    ```<a
             href="javascript:{}"
             onclick="document.getElementById('logout').submit();" // add the id to the form
             ><span class="material-icons">exit_to_app</span>{{_("Log Out")}}</a
           >```
   - You'll need to match the styles from `.dropdown-menu > li > a > .material-icons` in material-icons.css and from `.dropdown-menu > li > a` in `bootstrap-theme.css` 
   



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org