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

Url encoding issue/question #32429

Closed
BaronGreenback opened this issue May 5, 2021 · 5 comments
Closed

Url encoding issue/question #32429

BaronGreenback opened this issue May 5, 2021 · 5 comments

Comments

@BaronGreenback
Copy link

@BaronGreenback BaronGreenback commented May 5, 2021

After some assistance as i've looked everywhere.

Does kestrel support GET url decoding?

Encoded url:
http://192.168.1.5:8096/videos/69ee0a24-62a0-b9a7-2dc0-1f76993b43bf/stream.ts?ext=.strm%26DeviceProfileId=17c183c51f164cbcbaa8562915daabf1%26DeviceId=test%26MediaSourceId=69ee0a2462a0b9a72dc01f76993b43bf%26Static=true%26Tag=556b2d8f824b13c11ec3ef580ef73d85%26dlna=true

http://192.168.1.5:8096/videos/69ee0a24-62a0-b9a7-2dc0-1f76993b43bf/stream.ts%3Fext=.strm%26DeviceProfileId=17c183c51f164cbcbaa8562915daabf1%26DeviceId=test%26MediaSourceId=69ee0a2462a0b9a72dc01f76993b43bf%26Static=true%26Tag=556b2d8f824b13c11ec3ef580ef73d85%26dlna=true

Code:

        [HttpGet("{itemId}/stream.{container}")]
        [HttpHead("{itemId}/stream.{container}", Name = "HeadVideoStreamByContainer")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesVideoFile]
        public Task<ActionResult> GetVideoStreamByContainer(
            [FromRoute, Required] Guid itemId,
            [FromRoute, Required] string container,
            [FromQuery] bool? @static,
            [FromQuery] string? @params,
            [FromQuery] string? tag,
            [FromQuery] string? deviceProfileId,
            [FromQuery] string? playSessionId,
            [FromQuery] string? segmentContainer,
            [FromQuery] int? segmentLength,
            [FromQuery] int? minSegments,
            [FromQuery] string? mediaSourceId,
            [FromQuery] string? deviceId,
            [FromQuery] string? audioCodec,
            [FromQuery] bool? enableAutoStreamCopy,
            [FromQuery] bool? allowVideoStreamCopy,
            [FromQuery] bool? allowAudioStreamCopy,
            [FromQuery] bool? breakOnNonKeyFrames,
            [FromQuery] int? audioSampleRate,
            [FromQuery] int? maxAudioBitDepth,
            [FromQuery] int? audioBitRate,
            [FromQuery] int? audioChannels,
            [FromQuery] int? maxAudioChannels,
            [FromQuery] string? profile,
            [FromQuery] string? level,
            [FromQuery] float? framerate,
            [FromQuery] float? maxFramerate,
            [FromQuery] bool? copyTimestamps,
            [FromQuery] long? startTimeTicks,
            [FromQuery] int? width,
            [FromQuery] int? height,
            [FromQuery] int? videoBitRate,
            [FromQuery] int? subtitleStreamIndex,
            [FromQuery] SubtitleDeliveryMethod? subtitleMethod,
            [FromQuery] int? maxRefFrames,
            [FromQuery] int? maxVideoBitDepth,
            [FromQuery] bool? requireAvc,
            [FromQuery] bool? deInterlace,
            [FromQuery] bool? requireNonAnamorphic,
            [FromQuery] int? transcodingMaxAudioChannels,
            [FromQuery] int? cpuCoreLimit,
            [FromQuery] string? liveStreamId,
            [FromQuery] bool? enableMpegtsM2TsMode,
            [FromQuery] string? videoCodec,
            [FromQuery] string? subtitleCodec,
            [FromQuery] string? transcodeReasons,
            [FromQuery] int? audioStreamIndex,
            [FromQuery] int? videoStreamIndex,
            [FromQuery] EncodingContext? context,
            [FromQuery] Dictionary<string, string> streamOptions,
            [FromQuery] string? ext)

If the url contains ?, itemid and container are being populated - with the rest of the querystring unescaped and assigned to ext.

Tried the second, just to see if it was expecting the ? to be encoded.

Is this as designed, or am i doing something stupid?

@BrennanConroy
Copy link
Contributor

@BrennanConroy BrennanConroy commented May 5, 2021

Are you doing some custom encoding because the ? at the beginning of the query string should not be encoded and also the & between the different query parameters are not supposed to be encoded. If they are, then they are treated as part of the path.

Closing, this is by design.

@BaronGreenback
Copy link
Author

@BaronGreenback BaronGreenback commented May 5, 2021

Thanks for the reply.

The encoding is due to the DLNA specification - which states that URI's should be escaped. The responses are SOAP requests, so & has to be encoded, or else it is converted to &

By encoding the SOAP is kept valid, but the client is requesting escaped queries. Hence this query.

The system seems to partly detect this and unescape the querystring - but binding does not work.

I tried encoding the ? as i traced through the dotnet code and saw it is expecting a % in the path.

Hope this clarrifys.

@Tratcher
Copy link
Contributor

@Tratcher Tratcher commented May 5, 2021

The values you're sending are over-encoded and it changes the meaning of the uri fields.

Any value that's encoded specially to travel in a SOAP message must be decoded on receipt before it can be used. E.g. the client needs to decode the value it received before trying to use it as a uri to make requests to the server. What libraries are you using to encode the value before putting it into the SOAP message? That encoding should be reversible by the client.

@BaronGreenback
Copy link
Author

@BaronGreenback BaronGreenback commented May 6, 2021

I've tried multiple libraries - the above is the latest and not the best. The clients tend to be TV's etc some of which don't do any decoding - just using what has been sent to them. Hence my issue.

Ideally the design of the server could be changed but that's a massive piece of work.

I've got around it by implemented some middleware using IQueryfeature which decodings the querystring on receipt but wondered if there was anything inbuilt into dotnet as I've read it does some decoding on paths.

@Tratcher
Copy link
Contributor

@Tratcher Tratcher commented May 6, 2021

Asp.Net decodes urls after parsing them into components. Decoding before would risk changing the structure and meaning of the url. You can ask the folks at https://github.com/dotnet/wcf if they have suggestions for SOAP encodings.

@msftbot msftbot bot locked as resolved and limited conversation to collaborators Jun 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants