question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create action does not honor database policy

See original GitHub issue

In the current version the create action does not honor the specified database policy, which means that a request can create a new row in the database even if that row is outside the scope of the defined policy for that request. For example if I have the following entity:

"Todo": {
  "source": {
    "object": "dbo.todos",
    "type": "table"
  },
  "rest": {
    "path": "todo"
  },
  "permissions": [
    {
      "role": "anonymous",
      "actions": [
        {
          "action": "*",
          "policy": {
            "database": "@item.owner_id eq 'public'"
          }                                    
        }            
      ]        
    }                
  ]
}

I should not be able to send a POST request like the following:

curl --request POST \
  --url https://localhost:5001/api/todo \
  --header 'Content-Type: application/json' \
  --data '{   
  "title": "Testing policy",
  "completed": false,
  "owner_id": "hack!"
}'

but of course it works right now as the generate INSERT statement is the following:

INSERT INTO [dbo].[todos] ([title], [completed], [owner_id]) 
OUTPUT Inserted.[id], Inserted.[title], Inserted.[completed], Inserted.[owner_id] 
VALUES (@param0, @param1, @param2);

my proposal is to change the way the INSERT is generated so that DAB will generate the following SQL statement:

INSERT INTO [dbo].[todos] ([title], [completed], [owner_id]) 
OUTPUT Inserted.[id], Inserted.[title], Inserted.[completed], Inserted.[owner_id] 
SELECT [title], [completed], [owner_id]
FROM (VALUES  (@param0, @param1, @param2)) T([title], [completed], [owner_id])
WHERE [owner_id] = @param_from_policy

so that all values that are not compatible with the policy will be filtered out by the WHERE clause (as it happens for other statements)

Issue Analytics

  • State:closed
  • Created 7 months ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Aniruddh25commented, Feb 9, 2023

@seantleonard Lets document this in your PR: #1215 that database policy is not supported for create action

1reaction
Aniruddh25commented, Feb 9, 2023

Yeah, I didn’t mean like a physical temporary table - but more like conceptual. Meant to say like a result set.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Provision access by data owner for Azure SQL Database ...
This guide covers how a data owner can delegate authoring policies in Microsoft Purview to enable access to Azure SQL Database. The following ......
Read more >
Classic Business rules
A business rule is a server-side script that runs when a record is displayed, ... Business rules do not honor ACLs until you...
Read more >
15 Recovery Appliance Error Message Reference
Cause : An attempt was made to move the specified database to a new storage location, but the database could not be shrunk...
Read more >
Honor “Do Not Share” and "Do Not Sell" Requests in Data ...
Create a custom field in the Individual DMO to store Do Not Share or Do Not Sell request data. Map your Do Not...
Read more >
ACM Code of Ethics and Professional Conduct
1.4 Be fair and take action not to discriminate. 1.5 Respect the work required to produce new ideas, inventions, creative works, and computing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found