Skip to content
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

URI validation for winget cli commands #4707

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

AmelBawa-msft
Copy link
Contributor

@AmelBawa-msft AmelBawa-msft commented Aug 5, 2024

Description

flowchart TD
    %%{init:{'flowchart':{"defaultRenderer": "elk"}}}%%
    A[winget cli] --> B
    B{is configuration?} --> |yes| C[Get URI Zone]
    B --> |no| D{Package catalog trusted?}
    D --> |no| C
    D --> |yes| E(Resume operation)
    C --> F{Zone blocked by policy?}
    F -->|yes| G(APPINSTALLER_CLI_ERROR_BLOCKED_BY_POLICY)
    F --> |no| H{Zone Internet or Untrusted?}
    H --> |yes| I{SmartScreen blocked by policy?}
    H --> |no| E
    I --> |no| J{Blocked by SmartScreen?}
    I --> |yes| E
    J --> |yes| K(APPINSTALLER_CLI_ERROR_BLOCKED_BY_REPUTATION_SERVICE)
    J --> |no| E

    style G fill:red,stroke:darkred,color:white
    style K fill:red,stroke:darkred,color:white
    style E fill:green,stroke:darkgreen,color:white
Loading

TODO

  • Finalize strings

Follow ups

  • Add MotW HostUrl validation (TODO link to issue)
Microsoft Reviewers: Open in CodeFlow

auto isAllowed = configurationPolicies->at(zone);
if(!isAllowed)
{
context.Reporter.Error() << "Configuration is disabled for Zone: " << zone << std::endl;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO:

  • Finalizing strings
  • Move to resource file

@@ -122,6 +122,10 @@ If you disable this setting, users will not be able to use the Windows Package M
If you disable or do not configure this setting, no proxy will be used by default.

If you enable this setting, the specified proxy will be used by default.</string>
<string id="EnableDSCAllowedZones">Enable App Installer Allowed Zones for DSC</string>
<string id="EnableDSCAllowedZonesExplanation"></string>
Copy link
Member

Choose a reason for hiding this comment

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

Waiting for PM input?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but also, we're still thinking about the scope that this policy should cover (DSC only, or more ... )

switch (response.Decision())
{
case AppInstaller::UriValidation::UriValidationDecision::Block:
context.Reporter.Error() << std::endl << "Blocked by smart screen" << std::endl << "Feedback: " << response.Feedback() << std::endl;
Copy link
Member

Choose a reason for hiding this comment

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

If Feedback isn't localized, it should probably only be sent to the log and not stdout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All strings are not finalized/localized yet, there's an email thread for deciding on a couple things including localization

src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp Outdated Show resolved Hide resolved
src/Internal/UriValidation/UriValidation.cpp Show resolved Hide resolved
src/Internal/UriValidation/pch.h Outdated Show resolved Hide resolved
src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp Outdated Show resolved Hide resolved
src/AppInstallerSharedLib/Public/winget/GroupPolicy.h Outdated Show resolved Hide resolved
src/Internal/UriValidation/UriValidation.cpp Show resolved Hide resolved
// The decision made based on the Uri validation.
enum class UriValidationDecision
{
Allow,
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't there also a Warn response that SmartScreen can return?

https://learn.microsoft.com/en-us/defender-endpoint/web-protection-overview#order-of-precedence

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, there's a PUA response as well. However, PUA/Warn will also be treated as Blocked, but the details will be communicated in the logs instead and the logic will be in the injected code. I can potentially reduce this enum to a bool. I will revisit this later once things are a little bit more finalized.

src/Internal/UriValidation/UriValidation.h Show resolved Hide resolved
// Uri to give feedback to smart screen about the decision.
std::string m_feedback;
public:
UriValidationResult(UriValidationDecision decision) : m_decision(decision), m_feedback(std::string()) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a default (enpty) constructor?

src/Internal/UriValidation/UriValidation.cpp Outdated Show resolved Hide resolved
<None Include="packages.config" Condition="Exists('$(MSBuildProjectDirectory)\packages.config')" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CppWinRT" Version="2.0.230706.1" TargetFramework="native" />
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesnt seem to match the version of cppwinrt in NOTICE.txt. Does the version need to be bumped across all the solution files, or is there something I’m missing?

Microsoft.Windows.CppWinRT 2.0.210503.1 - MIT

@AmelBawa-msft AmelBawa-msft changed the title Validate configuration Urls URI validation for winget cli commands Oct 17, 2024
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.

3 participants