-
-
Notifications
You must be signed in to change notification settings - Fork 175
Prevent SQL source disclosure through path aliases #1476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- SQLPAGE_SOURCE_CANARY: this comment must never be returned over HTTP. | ||
| SELECT 'text' AS component, 'SQL executed' AS contents; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| use actix_web::{body::to_bytes, http::StatusCode}; | ||
| use sqlpage::webserver::http::main_handler; | ||
|
|
||
| use crate::common::get_request_to; | ||
|
|
||
| async fn assert_sql_response(path: &str, expected_status: StatusCode) { | ||
| let request = get_request_to(path).await.unwrap().to_srv_request(); | ||
| let response = match main_handler(request).await { | ||
| Ok(response) => response.into_parts().1, | ||
| Err(error) => error.error_response(), | ||
| }; | ||
| assert_eq!(response.status(), expected_status, "{path}"); | ||
| let body = to_bytes(response.into_body()).await.unwrap(); | ||
| let body = String::from_utf8(body.to_vec()).unwrap(); | ||
| assert!(!body.contains("SQLPAGE_SOURCE_CANARY"), "{path}: {body}"); | ||
| if expected_status == StatusCode::OK { | ||
| assert!(body.starts_with("<!DOCTYPE html>"), "{path}: {body}"); | ||
| assert!(body.contains("SQL executed"), "{path}: {body}"); | ||
| } | ||
| } | ||
|
|
||
| #[actix_web::test] | ||
| async fn mixed_case_sql_file_is_executed() { | ||
| assert_sql_response("/tests/core/mixed_case.%53ql", StatusCode::OK).await; | ||
| } | ||
|
|
||
| #[actix_web::test] | ||
| async fn trailing_space_sql_path_is_forbidden() { | ||
| assert_sql_response("/tests/core/sql_source.sql%20", StatusCode::FORBIDDEN).await; | ||
| } | ||
|
|
||
| #[cfg(windows)] | ||
| async fn assert_windows_alias_response(path: &str, expected_status: StatusCode) { | ||
| // Establish that this spelling really reaches the SQL source on this filesystem. | ||
| let source = std::fs::read(path.strip_prefix('/').unwrap()).unwrap(); | ||
| assert_eq!(source, include_bytes!("sql_source.sql")); | ||
| assert_sql_response(path, expected_status).await; | ||
| } | ||
|
|
||
| #[cfg(windows)] | ||
| #[actix_web::test] | ||
| async fn windows_mixed_case_sql_alias_is_executed() { | ||
| assert_windows_alias_response("/tests/core/sql_source.SQL", StatusCode::OK).await; | ||
| } | ||
|
|
||
| #[cfg(windows)] | ||
| #[actix_web::test] | ||
| async fn windows_trailing_dot_sql_alias_is_forbidden() { | ||
| assert_windows_alias_response("/tests/core/sql_source.sql.", StatusCode::FORBIDDEN).await; | ||
| } | ||
|
|
||
| #[cfg(windows)] | ||
| #[actix_web::test] | ||
| async fn windows_ntfs_stream_sql_alias_is_forbidden() { | ||
| assert_windows_alias_response("/tests/core/sql_source.sql::$DATA", StatusCode::FORBIDDEN).await; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- SQLPAGE_SOURCE_CANARY: this comment must never be returned over HTTP. | ||
| SELECT 'text' AS component, 'SQL executed' AS contents; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] this shouldn't be a comment, it should be 3 different tests we can run in the CI. I see you have some of them already