Skip to content

Conversation

@sayondeep
Copy link
Contributor

Summary

Fixes #41483

Testing

CI

Copy link
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 adds URL validation using the uriparser library, which is a good approach. The changes correctly add the new dependency to the build system. In the implementation, I've suggested a few improvements for correctness, efficiency, and code clarity. Specifically, I recommend making the scheme validation case-insensitive as per RFC 3986 and enhancing isValidRFC3986Uri to also check for query and fragment components. This avoids redundant processing and makes the validation logic more efficient and maintainable.

Comment on lines +48 to +55
bool hasHttpsScheme(const UriUriA & uri)
{
if (!uri.scheme.first || !uri.scheme.afterLast)
return false;

std::string scheme(uri.scheme.first, uri.scheme.afterLast);
return scheme == "https";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

According to RFC 3986, the scheme component is case-insensitive. The current implementation performs a case-sensitive comparison with "https". This should be changed to a case-insensitive comparison.

Additionally, creating a std::string for comparison is inefficient as it can cause heap allocation. A direct character-by-character comparison can avoid this.

You will need to include <cctype> for the tolower function.

bool hasHttpsScheme(const UriUriA & uri)
{
    if (!uri.scheme.first || !uri.scheme.afterLast)
    {
        return false;
    }

    const char * scheme_start = uri.scheme.first;
    const size_t scheme_len   = static_cast<size_t>(uri.scheme.afterLast - uri.scheme.first);
    constexpr char https_scheme[] = "https";
    constexpr size_t https_scheme_len = sizeof(https_scheme) - 1;

    if (scheme_len != https_scheme_len)
    {
        return false;
    }

    for (size_t i = 0; i < https_scheme_len; ++i)
    {
        if (tolower(scheme_start[i]) != https_scheme[i])
        {
            return false;
        }
    }

    return true;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

The code from Gemini above is cruddy, but the comment is correct.

Please:

  • Create a new src/lib/support/StringComparison.h and associated unit test
  • Have a new method for string view case insensitive compare:
#include <string_view>
#include <cctype>
#include <algorithm>

//// NAMESPACE IT properly

bool CaseInsensitiveCompare(std::string_view left, std::string_view right) {
    if (left.length() != right.length()) {
        return false; // Lengths differ, so they cannot be equal case-insensitively
    }

    for (size_t i = 0; i < left.length(); ++i) {
        // Convert characters to lowercase for comparison
        if (std::tolower(static_cast<unsigned char>(left[i])) !=
            std::tolower(static_cast<unsigned char>(right[i]))) {
            return false; // Characters differ after case conversion
        }
    }
    return true; // All characters matched after case conversion
}

Comment on lines +57 to +72
bool isValidRFC3986Uri(const std::string & uriStr)
{
UriUriA uri;
const char * errorPos;

int result = uriParseSingleUriA(&uri, uriStr.c_str(), &errorPos);
if (result != URI_SUCCESS)
{
return false;
}

bool isHttps = hasHttpsScheme(uri);

uriFreeUriMembersA(&uri);
return isHttps;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To make the URL validation more efficient, you can extend this function to also check for the presence of a query or fragment, since uriparser already provides this information after parsing. This avoids scanning the URL string again in ValidateUrl. The checks in ValidateUrl for '?' and '#' would then become redundant and could be removed in a follow-up change.

bool isValidRFC3986Uri(const std::string & uriStr)
{
    UriUriA uri;
    const char * errorPos;

    if (uriParseSingleUriA(&uri, uriStr.c_str(), &errorPos) != URI_SUCCESS)
    {
        return false;
    }

    bool isHttps     = hasHttpsScheme(uri);
    bool hasQuery    = (uri.query.first != nullptr);
    bool hasFragment = (uri.fragment.first != nullptr);

    uriFreeUriMembersA(&uri);
    return isHttps && !hasQuery && !hasFragment;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This validation has to happen for all URIs, but the query/fragment bits only need to happen for CMAF URIs. So the bot's advice here would only work if this function had a way to configure whether query/fragment are allowed.

@github-actions
Copy link

github-actions bot commented Oct 17, 2025

PR #41502: Size comparison from a95f163 to c0610c6

Full report (28 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, qpg, realtek, stm32, telink)
platform target config section a95f163 c0610c6 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1106366 1106366 0 0.0
RAM 178802 178802 0 0.0
bl702 lighting-app bl702+eth FLASH 660956 660956 0 0.0
RAM 134881 134881 0 0.0
bl702+wifi FLASH 837068 837068 0 0.0
RAM 124349 124349 0 0.0
bl706+mfd+rpc+littlefs FLASH 1070036 1070036 0 0.0
RAM 117189 117189 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 898878 898878 0 0.0
RAM 105468 105468 0 0.0
lighting-app bl702l+mfd+littlefs FLASH 983054 983054 0 0.0
RAM 109676 109676 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 770364 770364 0 0.0
RAM 103240 103240 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 782120 782120 0 0.0
RAM 108400 108400 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 727940 727940 0 0.0
RAM 97308 97308 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 712384 712384 0 0.0
RAM 97508 97508 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 554066 554066 0 0.0
RAM 205504 205504 0 0.0
lock CC3235SF_LAUNCHXL FLASH 587318 587318 0 0.0
RAM 205768 205768 0 0.0
efr32 lock-app BRD4187C FLASH 962192 962192 0 0.0
RAM 126268 126268 0 0.0
BRD4338a FLASH 757728 757720 -8 -0.0
RAM 255540 255540 0 0.0
window-app BRD4187C FLASH 1057460 1057452 -8 -0.0
RAM 122464 122464 0 0.0
qpg lighting-app qpg6200+debug FLASH 836552 836552 0 0.0
RAM 127644 127644 0 0.0
lock-app qpg6200+debug FLASH 773252 773252 0 0.0
RAM 118620 118620 0 0.0
realtek light-switch-app rtl8777g FLASH 706224 706224 0 0.0
RAM 106800 106800 0 0.0
lighting-app rtl8777g FLASH 757320 757320 0 0.0
RAM 127164 127164 0 0.0
stm32 light STM32WB5MM-DK FLASH 469812 469812 0 0.0
RAM 141248 141248 0 0.0
telink bridge-app tl7218x FLASH 710462 710462 0 0.0
RAM 90436 90436 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 796848 796848 0 0.0
RAM 40936 40936 0 0.0
light-app-ota-shell-factory-data tl7218x FLASH 788048 788048 0 0.0
RAM 93580 93580 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 714974 714974 0 0.0
RAM 51736 51736 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 748278 748278 0 0.0
RAM 70784 70784 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 725126 725126 0 0.0
RAM 34484 34484 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 602366 602366 0 0.0
RAM 108628 108628 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 820668 820672 4 0.0
RAM 91976 91976 0 0.0


// Check minimum length and https prefix
if (url.size() <= https.size() || url.substr(0, https.size()) != https)
if (!isValidRFC3986Uri(url))
Copy link
Contributor

@vnkavali vnkavali Oct 17, 2025

Choose a reason for hiding this comment

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

11.7.6.13. TransportOptionsStruct Type
11.7.6.13.5. URL Field
This field SHALL be a valid string in RFC 3986 format representing the upload location. The field
SHALL use the https scheme which will be validated by the underlying TLSEndpointID.

These RFC Checks are for all Transports, while the following invalid character checks are CMAF-specific in the spec.
More details at https://github.com/CHIP-Specifications/connectedhomeip-spec/issues/12442 and Full discussion at #41321 (comment).

Also, heads up - #41321 addresses other issues in this API and also call this only when ContainerType is CMAF. So would need to rebase to it once it's merged.

@sayondeep sayondeep force-pushed the pr/pushav_rfc3986 branch 2 times, most recently from 5344b5c to d0d13e2 Compare October 17, 2025 12:27
@sayondeep sayondeep changed the title [Pusha AV]: Add url validation as per rfc3986 [Push AV]: Add url validation as per rfc3986 Oct 17, 2025
@sayondeep sayondeep changed the title [Push AV]: Add url validation as per rfc3986 [Push AV]: Add url validation as per RFC3986 Oct 17, 2025
@github-actions
Copy link

github-actions bot commented Oct 17, 2025

PR #41502: Size comparison from 43e4daf to 911d797

Full report (28 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, qpg, realtek, stm32, telink)
platform target config section 43e4daf 911d797 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1106366 1106366 0 0.0
RAM 178802 178802 0 0.0
bl702 lighting-app bl702+eth FLASH 660956 660956 0 0.0
RAM 134881 134881 0 0.0
bl702+wifi FLASH 837068 837068 0 0.0
RAM 124349 124349 0 0.0
bl706+mfd+rpc+littlefs FLASH 1070036 1070036 0 0.0
RAM 117189 117189 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 898878 898878 0 0.0
RAM 105468 105468 0 0.0
lighting-app bl702l+mfd+littlefs FLASH 983054 983054 0 0.0
RAM 109676 109676 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 770364 770364 0 0.0
RAM 103240 103240 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 782120 782120 0 0.0
RAM 108400 108400 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 727940 727940 0 0.0
RAM 97308 97308 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 712384 712384 0 0.0
RAM 97508 97508 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 554066 554066 0 0.0
RAM 205504 205504 0 0.0
lock CC3235SF_LAUNCHXL FLASH 587318 587318 0 0.0
RAM 205768 205768 0 0.0
efr32 lock-app BRD4187C FLASH 962192 962192 0 0.0
RAM 126268 126268 0 0.0
BRD4338a FLASH 757728 757720 -8 -0.0
RAM 255540 255540 0 0.0
window-app BRD4187C FLASH 1057460 1057452 -8 -0.0
RAM 122464 122464 0 0.0
qpg lighting-app qpg6200+debug FLASH 836552 836552 0 0.0
RAM 127644 127644 0 0.0
lock-app qpg6200+debug FLASH 773252 773252 0 0.0
RAM 118620 118620 0 0.0
realtek light-switch-app rtl8777g FLASH 706224 706224 0 0.0
RAM 106800 106800 0 0.0
lighting-app rtl8777g FLASH 757320 757320 0 0.0
RAM 127164 127164 0 0.0
stm32 light STM32WB5MM-DK FLASH 469812 469812 0 0.0
RAM 141248 141248 0 0.0
telink bridge-app tl7218x FLASH 710462 710462 0 0.0
RAM 90436 90436 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 796848 796848 0 0.0
RAM 40936 40936 0 0.0
light-app-ota-shell-factory-data tl7218x FLASH 788048 788048 0 0.0
RAM 93580 93580 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 714974 714974 0 0.0
RAM 51736 51736 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 748278 748278 0 0.0
RAM 70784 70784 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 725126 725126 0 0.0
RAM 34484 34484 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 602366 602366 0 0.0
RAM 108628 108628 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 820668 820672 4 0.0
RAM 91976 91976 0 0.0

@codecov
Copy link

codecov bot commented Oct 17, 2025

Codecov Report

❌ Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.06%. Comparing base (a95f163) to head (e937127).
⚠️ Report is 32 commits behind head on master.

Files with missing lines Patch % Lines
...ransport-server/push-av-stream-transport-logic.cpp 81.25% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #41502      +/-   ##
==========================================
+ Coverage   51.01%   51.06%   +0.04%     
==========================================
  Files        1386     1384       -2     
  Lines      100988   100900      -88     
  Branches    13081    13057      -24     
==========================================
+ Hits        51519    51523       +4     
+ Misses      49469    49377      -92     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines 13 to 14
action("build_uriparser") {
script = "scripts/build_uriparser.py"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can this not be a portable BUILD.gn target? This overrides a lot of the build infra in a non portable way.

Comment on lines 8 to 39
@click.command()
@click.option("--clang", is_flag=True, default=False, help="Use clang instead of gcc")
@click.option("--output-dir", default="build", help="Output directory for uriparser build")
def main(clang, output_dir):
script_dir = os.path.dirname(os.path.abspath(__file__))
repo_dir = os.path.join(script_dir, "..", "repo")
build_dir = os.path.join(repo_dir, output_dir)

# CMake command
cmake_cmd = [
"cmake",
"-B", build_dir,
"-DCMAKE_BUILD_TYPE=Release",
"-DBUILD_SHARED_LIBS=OFF",
"-DURIPARSER_BUILD_TESTS=OFF",
"-DURIPARSER_BUILD_DOCS=OFF"
]

if clang:
cmake_cmd += ["-DCMAKE_C_COMPILER=clang", "-DCMAKE_CXX_COMPILER=clang++"]
else:
cmake_cmd += ["-DCMAKE_C_COMPILER=gcc", "-DCMAKE_CXX_COMPILER=g++"]

print("Running:", " ".join(cmake_cmd))
subprocess.run(cmake_cmd, cwd=repo_dir, check=True)

# Build
make_cmd = ["make", "-j", str(os.cpu_count())]
print("Running:", " ".join(make_cmd))
subprocess.run(make_cmd, cwd=build_dir, check=True)

print("uriparser build complete at", build_dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

This only works for some platforms and likely just in CI. Why does this need to be a new dep?

Copy link
Contributor

@tcarmelveilleux tcarmelveilleux left a comment

Choose a reason for hiding this comment

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

  • Consider avoiding new dependency, unless it is portably built
  • New code requires unit tests for passing/failing URI
  • Add necessary reusable case insensitive string compare

@github-actions
Copy link

github-actions bot commented Oct 21, 2025

PR #41502: Size comparison from 43e4daf to e937127

Increases above 0.2%:

platform target config section 43e4daf e9371274 change % change
efr32 lock-app BRD4338a RAM 255540 256952 1412 0.6
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1676484 1685476 8992 0.5
telink light-switch-app-ota-factory-data tl3218x_retention RAM 34484 34592 108 0.3
Full report (32 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, psoc6, qpg, realtek, stm32, telink)
platform target config section 43e4daf e9371274 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1106366 1106622 256 0.0
RAM 178802 178874 72 0.0
bl702 lighting-app bl702+eth FLASH 660956 661198 242 0.0
RAM 134881 134969 88 0.1
bl702+wifi FLASH 837068 837310 242 0.0
RAM 124349 124405 56 0.0
bl706+mfd+rpc+littlefs FLASH 1070036 1070278 242 0.0
RAM 117189 117261 72 0.1
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 898878 899120 242 0.0
RAM 105468 105524 56 0.1
lighting-app bl702l+mfd+littlefs FLASH 983054 983040 -14 -0.0
RAM 109676 109740 64 0.1
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 770364 770636 272 0.0
RAM 103240 103304 64 0.1
lock-ftd LP_EM_CC1354P10_6 FLASH 782120 782368 248 0.0
RAM 108400 108472 72 0.1
pump-app LP_EM_CC1354P10_6 FLASH 727940 728196 256 0.0
RAM 97308 97364 56 0.1
pump-controller-app LP_EM_CC1354P10_6 FLASH 712384 712656 272 0.0
RAM 97508 97580 72 0.1
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 554066 554330 264 0.0
RAM 205504 205736 232 0.1
lock CC3235SF_LAUNCHXL FLASH 587318 587578 260 0.0
RAM 205768 205832 64 0.0
efr32 lock-app BRD4187C FLASH 962192 963160 968 0.1
RAM 126268 126328 60 0.0
BRD4338a FLASH 757728 756712 -1016 -0.1
RAM 255540 256952 1412 0.6
window-app BRD4187C FLASH 1057460 1058452 992 0.1
RAM 122464 122556 92 0.1
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1676484 1685476 8992 0.5
RAM 213660 213924 264 0.1
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1592556 1593244 688 0.0
RAM 210956 211108 152 0.1
light cy8ckit_062s2_43012 FLASH 1459172 1459788 616 0.0
RAM 197656 197728 72 0.0
lock cy8ckit_062s2_43012 FLASH 1491724 1492340 616 0.0
RAM 225376 225440 64 0.0
qpg lighting-app qpg6200+debug FLASH 836552 837088 536 0.1
RAM 127644 127708 64 0.1
lock-app qpg6200+debug FLASH 773252 773868 616 0.1
RAM 118620 118684 64 0.1
realtek light-switch-app rtl8777g FLASH 706224 706584 360 0.1
RAM 106800 106904 104 0.1
lighting-app rtl8777g FLASH 757320 757672 352 0.0
RAM 127164 127236 72 0.1
stm32 light STM32WB5MM-DK FLASH 469812 470076 264 0.1
RAM 141248 141304 56 0.0
telink bridge-app tl7218x FLASH 710462 710558 96 0.0
RAM 90436 90544 108 0.1
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 796848 796912 64 0.0
RAM 40936 41000 64 0.2
light-app-ota-shell-factory-data tl7218x FLASH 788048 788112 64 0.0
RAM 93580 93644 64 0.1
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 714974 714998 24 0.0
RAM 51736 51844 108 0.2
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 748278 748302 24 0.0
RAM 70784 70892 108 0.2
light-switch-app-ota-factory-data tl3218x_retention FLASH 725126 725150 24 0.0
RAM 34484 34592 108 0.3
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 602366 602428 62 0.0
RAM 108628 108692 64 0.1
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 820668 820736 68 0.0
RAM 91976 92040 64 0.1

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.

Missing implementation for URL SHALL be valid as per RFC 3986 as mandated in Push AV Spec

4 participants