Skip to content

fix: validate CAPABILITY arguments (closes #260)#262

Open
Deepak8858 wants to merge 2 commits intoLSFLK:mainfrom
Deepak8858:fix/issue-260-capability-args
Open

fix: validate CAPABILITY arguments (closes #260)#262
Deepak8858 wants to merge 2 commits intoLSFLK:mainfrom
Deepak8858:fix/issue-260-capability-args

Conversation

@Deepak8858
Copy link
Copy Markdown

RFC 3501 specifies that the CAPABILITY command takes no arguments. This PR adds validation to return BAD if arguments are provided, ensuring better compliance with the IMAP protocol.

Fixes #260

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 29, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ Deepak Singh
❌ Adityasingh-upkgs


Deepak Singh seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the HandleCapability function to enforce RFC 3501 compliance by ensuring no arguments are passed to the command. The function signature now includes the command parts, and all references in the codebase and tests have been updated. Feedback identifies a critical syntax error in capability_test.go that causes a compilation failure and suggests adding a test case to verify the new validation logic.

for i, state := range states {
conn := server.NewMockConn()
srv.HandleCapability(conn, fmt.Sprintf("STATE%d", i), state)
srv.HandleCapability(conn, fmt.Sprintf("STATE%d", []string{fmt.Sprintf("STATE%d", "CAPABILITY"}, i), state)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

This line appears to have a copy-paste error that will cause a compilation failure. The arguments to fmt.Sprintf are incorrect, and the arguments to HandleCapability are misplaced.

Suggested change
srv.HandleCapability(conn, fmt.Sprintf("STATE%d", []string{fmt.Sprintf("STATE%d", "CAPABILITY"}, i), state)
srv.HandleCapability(conn, fmt.Sprintf("STATE%d", i), []string{fmt.Sprintf("STATE%d", i), "CAPABILITY"}, state)

Comment on lines +42 to +45
if len(parts) > 2 {
deps.SendResponse(conn, fmt.Sprintf("%s BAD CAPABILITY takes no arguments", tag))
return
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This argument validation is a good addition for RFC compliance. To ensure it works as expected and prevent future regressions, it would be beneficial to add a test case for this failure scenario.

You could add the following sub-test to TestCapabilityCommand_EdgeCases in internal/server/auth/capability_test.go:

t.Run("WithArguments", func(t *testing.T) {
	srv := server.SetupTestServerSimple(t)
	conn := server.NewMockConn()
	state := &models.ClientState{Authenticated: false}

	tag := "ARGTEST"
	parts := []string{tag, "CAPABILITY", "some_arg"}
	srv.HandleCapability(conn, tag, parts, state)

	response := conn.GetWrittenData()
	expected := fmt.Sprintf("%s BAD CAPABILITY takes no arguments\\r\\n", tag)
	if response != expected {
		t.Errorf("Expected response '%s', got '%s'", expected, response)
	}
})

@maneeshaxyz
Copy link
Copy Markdown
Member

Hi @Deepak8858, thank you for wanting to contribute to the Raven codebase. We ask all our contributors to sign our CLA. You can do so by clicking the link left by the CLA assistant. Once you have done so, please fix the issues picked up by the ci and the merge conflicts. Feel free to tag me and @Aravinda-HWK, once you are done and we will review it.

Thank you for your contribution.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] CAPABILITY accepts invalid arguments

4 participants