Skip to content

python: model send_header from http.server #19432

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

yoff
Copy link
Contributor

@yoff yoff commented Apr 30, 2025

Requested here

@Copilot Copilot AI review requested due to automatic review settings April 30, 2025 17:59
@yoff yoff requested a review from a team as a code owner April 30, 2025 17:59
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR models the send_header method from http.server for CodeQL analysis by updating tests and adding a new QL class.

  • Adds CodeQL taint annotations to the HTTP server test file.
  • Introduces HeaderWriteCall in the Stdlib QL library to capture header write calls.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
python/ql/test/library-tests/frameworks/stdlib/http_server.py Added CodeQL annotations to the send_header call to mark unsanitized header write details.
python/ql/lib/semmle/python/frameworks/Stdlib.qll Added a new class, HeaderWriteCall, to model calls to send_header including associated taint handling.

override DataFlow::Node getValueArg() { result = this.getArg(1) }

// TODO: These checks perhaps could be made more precise.
override predicate nameAllowsNewline() { any() }
Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider refining the predicate for nameAllowsNewline if possible, rather than using a blanket 'any()' which may reduce the precision of the taint tracking.

Suggested change
override predicate nameAllowsNewline() { any() }
override predicate nameAllowsNewline() { not exists(this.getNameArg().toString().regexpMatch(".*[\n\r].*")) }

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not about the argument itself, but rather wether the server configuration would allow a newline to appear here. http.server does not have any protection against this, so any is correct.

// TODO: These checks perhaps could be made more precise.
override predicate nameAllowsNewline() { any() }

override predicate valueAllowsNewline() { any() }
Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider refining the predicate for valueAllowsNewline if feasible, to improve the accuracy of tracking header values in the taint analysis.

Suggested change
override predicate valueAllowsNewline() { any() }
override predicate valueAllowsNewline() {
not exists(DataFlow::Node value | value = this.getValueArg() |
value.toString().matches("%0A") or value.toString().matches("%0D")
)
}

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for the name argument above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant